'Print the collection of a dictionary

I have created a dictionary that consists of multiple collections, but the only way I could find to print the content of the Items to a sheet in columns was:

    j = 0
    For Each key In dict
     i = 1
     For Each values In dict(key)
        .Cells(1 + i, 1 + j).Value2 = values 
        i = i + 1
     Next
     j = j + 1
    Next

Can I use something like dict.Items or a faster way to do it?



Solution 1:[1]

this macro could help you.

Sub FillDictionaryWithUniqueValuesAndWriteToSheet()
  Dim Vardat As Variant
  Dim objDict As Object
  Dim lngRow As Long

  Set objDict = CreateObject("Scripting.Dictionary")

  With Sheet1

  Vardat = Application.Transpose(.Range([a1], .Cells(Rows.Count, "A").End(xlUp)))

  For lngRow = 1 To UBound(Vardat, 1)
      objDict(Vardat(lngRow)) = 1
  Next lngRow

   .Range("H:H").ClearContents
   .Range("H1:H" & objDict.Count) = Application.Transpose(objDict.keys)

  End With

End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BigBen