My typical use of dictionary

Actionimplementationcomment
Declare
Dim dict As Object late binding
Create
Set dict = CreateObject(“Scripting.Dictionary”)late binding
Change value at given keydict(Key) = newValue
dict(MyKeyVariable) = “MyNewItem”
can be used to add if the key doesn’t exist.
Storing number as textdict(MyNumber) = “‘” & MyNumber
Add new itemdict.Add Key, Value
dict.Add MyKeyVariable, “MyNewItem”
only to be used if key doesn’t exist
Check if key existsdict.Exists(Key)
If dict.Exists(MyKeyVariable) Then
Remove entry at Keydict.Remove KeyAll entries: dict.RemoveAll
Write all items to worksheet columnCells(1, 1).Resize(dict.Count) = Application.Transpose(dict.items)
Loop throughDim i As Long
For i = 0 To dict.Count – 1
Debug.Print dict.Keys()(i), dict.Items()(i)
Next i
works with both early and late binding