Dictionary is writing data to sheet

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

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
 

Attachments

  • Untitled.png
    Untitled.png
    15.8 KB · Views: 3

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
This line
VBA Code:
odict.Item(dkey).Value = odict.Item(dkey).Value & "," & Cells(q, 2).Value
should be
VBA Code:
odict.Item(dkey) = odict.Item(dkey) & "," & Cells(q, 2).Value
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,956
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top