Stephen_IV
Well-known Member
- Joined
- Mar 17, 2003
- Messages
- 1,176
- Office Version
- 365
- 2019
- Platform
- Windows
I am trying to learn dictionary. Somone gave me the code below. What I am trying to do is almost the same thing but instead of counting the item I would like to pull the items. Please see below. Thanks in advance!
to this:
|
VBA Code:
Sub CountGreaterThenTwo()
Dim xcell As Range
Dim i As Long
Dim r As Range
Dim dic As Object
Set r = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
For Each xcell In r
If xcell.Value <> "" Then
If Not dic.Exists(xcell.Value) Then
Set dic(xcell.Value) = CreateObject("Scripting.Dictionary")
End If
dic(xcell.Value)(xcell.Offset(0, 1).Value & "|" & xcell.Offset(0, 2).Value) = Empty
End If
Next xcell
i = 1
For Each k In dic.Keys
If dic(k).Count > 1 Then
i = i + 1
Cells(i, 10).Value = k
Cells(i, 11).Value = dic(k).Count
End If
Next k
End Sub
to this:
|