Action | implementation | comment |
Declare | Dim dict As Object | late binding |
Create | Set dict = CreateObject(“Scripting.Dictionary”) | late binding |
Change value at given key | dict(Key) = newValue dict(MyKeyVariable) = “MyNewItem” | can be used to add if the key doesn’t exist. |
Storing number as text | dict(MyNumber) = “‘” & MyNumber | |
Add new item | dict.Add Key, Value dict.Add MyKeyVariable, “MyNewItem” | only to be used if key doesn’t exist |
Check if key exists | dict.Exists(Key) If dict.Exists(MyKeyVariable) Then | |
Remove entry at Key | dict.Remove Key | All entries: dict.RemoveAll |
Write all items to worksheet column | Cells(1, 1).Resize(dict.Count) = Application.Transpose(dict.items) | |
Loop through | Dim 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 |