Iterate over VBA Dictionaries?

ExcelVba

Excel Problem Overview


I'm using the Dictionary class in the MS Runtime Scripting library to store where labels are going to go for a report template. Is there a way to iterate over all the key value pairs in that dictionary like in Python?

I just want to use the key as the row number (It's all going in column A) and the value will be the label header.

Something like:

For Each key in dict
    Range("A" & key).Value = dict(key)
Next key

Excel Solutions


Solution 1 - Excel

Try:

For Each varKey In oDic.Keys()
    Range("A" & varKey).Value = oDic(varKey)
Next

Note that the key iterator must be declared as a Variant.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmandroidView Question on Stackoverflow
Solution 1 - ExcelEBGreenView Answer on Stackoverflow