Exceladd1ct
Board Regular
- Joined
- Feb 10, 2019
- Messages
- 76
Hello,
This piece of code should group data from sheet into a dictionary,but for some reason, it also writes data to sheet.
Can anyone point where this cames from? Thanks
This piece of code should group data from sheet into a dictionary,but for some reason, it also writes data to sheet.
Can anyone point where this cames from? Thanks
VBA Code:
Option Explicit
Sub group_items()
Dim dkey As String
Dim odict As Object
Set odict = CreateObject("scripting.dictionary")
With odict
Dim q As Long
For q = 1 To Cells(Rows.Count, 1).End(xlUp).Row
dkey = Cells(q, 1).Value
If Not odict.exists(dkey) Then
odict.Add dkey, Cells(q, 2)
Else
odict.Item(dkey).Value = odict.Item(dkey).Value & "," & Cells(q, 2).Value
End If
Next
End With
Dim key As Variant
For Each key In odict.keys
Debug.Print key, odict(key)
Next
End Sub