Items - Add / Remove


oDict.Add key:="Mon", item:=10 
oDict.Add(key:="Tue", item:=20)
oDict.Add("Wed", 30)

The key can be any data type.
The item can be any data type.

A Dictionary object can also be used although to populate the dictionary you need to loop through the array.
This will also need a reference to the Microsoft Scripting Runtime library.

Public Function UsingDictionary(ByVal arValues As Variant, _ 
                                ByVal sFindValue As String) _
                                As Boolean
Dim MyDictionary As Scripting.Dictionary
Dim lposition As Long
Dim sreturn As String
   Set MyDictionary = New Scripting.Dictionary
   For lposition = 0 To UBound(arValues)
      MyDictionary.Add arValues(lposition), arValues(lposition)
   Next lposition
   UsingDictionary = MyDictionary.Exists(sFindValue)
End Function

Remove Method


RemoveAll Method

This method removes all items in the Dictionary object
A collection object on the other hand has no method for quickly removing all the items at once.
This can be achieved by setting the Collection to Nothing.

Adding Excel Ranges


You don't have to add a Range object, you can add Range.Value to store a 1 dimensional array.

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext