Option Explicit
Sub UserCollection()
' Declare and Create collection
Dim collFruit As New Collection
Dim x As String
' Add items
collFruit.Add "Apple", "X"
collFruit.Add "Pear", " green"
collFruit.Add "Plum", " purple"
x = InputBox("Enter Term ", "Search ")
' Print all items
Dim i As Long
For i = 1 To collFruit.Count
If collFruit(i) = x Then
MsgBox collFruit(i)
End If
Next i
End Sub
Sub UserDictionary()
' Declare and Create Dictionary
Dim Dict As Object
Set Dict = CreateObject("Scripting.Dictionary")
Dim x As String
' Add items
Dict.Add "Apple", "X"
Dict.Add "Pear", " green"
Dict.Add "Plum", " purple"
x = InputBox("Enter Term ", "Search ")
' Print all items
Dim i As Long
MsgBox x & " contains : " & CStr(Dict(x))
End Sub
As you can't query on "Apple" as it is an item an "X" the key !How can I query on " Apple " and return " X " ?
Option Explicit
Sub UserCollection()
' Declare and Create collection
Dim collFruit As New Collection
Dim x As String
' Add items
collFruit.Add "Apple", "X"
collFruit.Add "Pear", "green"
collFruit.Add "Plum", "purple"
x = InputBox("Enter Term ", "Search ")
' Print all items
'Dim i As Long
'For i = 1 To collFruit.Count
' If collFruit(i) = x Then
' MsgBox collFruit(i)
' End If
'Next i
' Print all items
Dim i As Long
MsgBox x & " contains : " & CStr(collFruit(x))
End Sub
No I just warned maybe you made an error in the use of the CollectionHui & Marc :
You are each recommending something different (Col / Dict).