(Solved) – VBA dictionary is empaty after delcaring it and populating

(solved)-–-vba-dictionary-is-empaty-after-delcaring-it-and-populating

I’m not so good with VBA, thus I’m suspecting an issue with declaring and later on using the dictionary.

All code is in one sub:

Dim list_columns As Dictionary
Dim list_format As Dictionary

Set list_columns = New Dictionary
Set list_format = New Dictionary

For row = 1 To count_rows
    list_columns.Add rng.Item(row, 2), CStr(rng.Item(row, 1))
Next row

count_rows = rng_format.Count / 2

For row = 1 To count_rows
    list_format.Add rng_format.Item(row, 1), "date"     
Next row

Later on when I try to use the dictionary (example below) and loop through both of them, the “list_format” shows as empty.. (after creating I’m checking with debuging and it’s populated correclty). Please advise what I’m doing wrong 😀

For Each key_c In list_columns.Keys
    For Each ctrl In Results.Controls
        If ctrl.Name = key_c Then
            Debug.Print key_c
            If list_format.Item(list_columns.Item(key_c)) = "date" Then
                ctrl = Format(Val(ListBox1.List(0, list_columns.Item(key_c) - 1)), "dd.mm.yyyy")
            Else
                ctrl = ListBox1.List(0, list_columns.Item(key_c) - 1)
            End If
        End If
    Next ctrl
Next key_c

Leave a Reply

Your email address will not be published. Required fields are marked *