Sub tes()
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
dic.Add "a", 1
dic.Add "b", 2
dic.Add "c", 3
Dim items() As Variant
items = dic.items
For Each itm In items
Debug.Print itm
Next itm
End Sub
@Kyle123
Not sure if I've misunderstood what you're saying, but you can use a for each loop on dictionary items.
Along the lines ofCode:For Each Itm In Dic.Items Ws1.Range("A" & Itm.Row).EntireRow.Insert Itm.EntireRow.Copy Ws1.Range("A" & Itm.Row) Next Itm
@Fluff
Items returns an array, your code is simply looping through the array returned by the items property.
It's shorthand for:
So a dictionary is not like a collection, one cannot enumerate its values as one can in a collectionCode:Sub tes() Dim dic As Object Set dic = CreateObject("scripting.dictionary") dic.Add "a", 1 dic.Add "b", 2 dic.Add "c", 3 Dim items() As Variant items = dic.items For Each itm In items Debug.Print itm Next itm End Sub
https://www.mrexcel.com/forum/excel-questions/1055806-pass-more-than-one-argument.html
Dim DIC As Scripting.Dictionary
Set DIC = New Scripting.Dictionary
DIC.Add Key:="Apple", Item:="Large"
DIC.Add Key:="Orange", Item:="Small"
Dim DICElement As Variant
For Each DICElement In DIC
Call SomeSub(Arg1:=DICElement, Arg2:=DIC.Item(DICElement))
Next DICElement
Dim DIC As Scripting.Dictionary
Set DIC = New Scripting.Dictionary
Dim keys() As Variant
DIC.Add Key:="Apple", Item:="Large"
DIC.Add Key:="Orange", Item:="Small"
keys = DIC.keys
Dim DICElement As Variant
For Each DICElement In keys
Call somesub(Arg1:=DICElement, Arg2:=DIC.Item(DICElement))
Next DICElement
No, it's not. What you have written is shorthand for:
Rich (BB code):Dim DIC As Scripting.Dictionary Set DIC = New Scripting.Dictionary Dim keys() As Variant DIC.Add Key:="Apple", Item:="Large" DIC.Add Key:="Orange", Item:="Small" keys = DIC.keys Dim DICElement As Variant For Each DICElement In keys Call somesub(Arg1:=DICElement, Arg2:=DIC.Item(DICElement)) Next DICElement
The Keys is implicit as it's the default member. So your code is looping through the array of keys returned by the key property.
You are then accessing the dictionary's values using the key.