iterating through a Dictionary object

B

Ben

Hi all,

Is there a way to iterating through the entire dictionary object. I want to
do a Debug.Print to see all the keys and the items values in the Immediate
Window.

Thanks in advance,

Ben


--
 
C

Chip Pearson

Try code like


Dim V As Variant
For Each V In Dict.Items
Debug.Print V
Next V

' or

Dim N As Long
For N = 0 To Dict.Count - 1
Debug.Print "Value: " & Dict.Items(N), "Key: " & Dict.Keys(N)
Next N


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
J

Jim Thomlinson

You can use a for each something like this...

Sub test()
Dim dic As Object
Dim dicItem As Variant

Set dic = CreateObject("Scripting.Dictionary")

dic.Add "this", "This"
dic.Add "That", "That"

For Each dicItem In dic
Debug.Print dicItem
Next dicItem

End Sub
 
B

Ben

Thanks Jim.

Ben

--



Jim Thomlinson said:
You can use a for each something like this...

Sub test()
Dim dic As Object
Dim dicItem As Variant

Set dic = CreateObject("Scripting.Dictionary")

dic.Add "this", "This"
dic.Add "That", "That"

For Each dicItem In dic
Debug.Print dicItem
Next dicItem

End Sub
 
B

Ben

Thanks Chip.

Ben


--



Chip Pearson said:
Try code like


Dim V As Variant
For Each V In Dict.Items
Debug.Print V
Next V

' or

Dim N As Long
For N = 0 To Dict.Count - 1
Debug.Print "Value: " & Dict.Items(N), "Key: " & Dict.Keys(N)
Next N


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top