Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Debug Print keys and values in dictionary using VBA?

Tags:

excel

vba

I am using vba and have written certain values into the dictionary. However, I would like to see if information has been passed into the dictionary correctly. Hence, is it possible to debug.print keys and values in a dictionary to the immediate window?

I was thinking of this:

debug.print DicTemp.Items

Thank you!

like image 494
Lucky0683 Avatar asked Jan 03 '23 03:01

Lucky0683


2 Answers

Public Sub TestMe()

    Dim dict As Object
    Set dict = CreateObject("Scripting.Dictionary")
    dict.Add "first", 30
    dict.Add "second", 40
    dict.Add "third", 100

    Dim key As Variant
    For Each key In dict.Keys
        Debug.Print key, dict(key)
    Next key

End Sub

It prints:

first          30 
second         40 
third          100 
like image 124
Vityata Avatar answered Mar 15 '23 02:03

Vityata


Loop through each dictionary key, and debug print:

Dim key As Variant
For Each key In dict.Keys
    Debug.Print key, dict(key)
Next key
like image 29
Olly Avatar answered Mar 15 '23 01:03

Olly