E
ExcelMonkey
In the routine below I do not have Option Explicit turned off. When I turn
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?
Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer
Set d = CreateObject("Scripting.Dictionary")
d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"
Items = d.Items
Keys = d.Keys
SearchTerm = "Rob"
Debug.Print "Arrray contains the following data:"
For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub
Thanks
EM
it on, I get error messages telling me that "Keys" and "Items" are not
defined. What do define them as?
Sub DictionaryDemo()
Dim d as Dictionary
Dim SearchTerm As String
Dim X As Integer
Set d = CreateObject("Scripting.Dictionary")
d.Add "Rob", "Athens" ' Add some keys and items.
d.Add "Barry", "Belgrade"
d.Add "Tim", "Cairo"
d.Add "Tom", "Edmonton"
d.Add "Sue", "Calgary"
d.Add "Sherry", "Vancouver"
d.Add "Brian", "Toronto"
d.Add "Anne", "New Jersey"
d.Add "Dave", "New York"
d.Add "Rick", "Houston"
Items = d.Items
Keys = d.Keys
SearchTerm = "Rob"
Debug.Print "Arrray contains the following data:"
For X = 0 To UBound(Keys)
If Keys(X) = "Rob" Then
Debug.Print Keys(X) & ": " & Items(X)
End If
Next
End Sub
Thanks
EM