多字典一次搞定,代码如下:
Sub TJ()
Dim i%, m%, n%, d1, d2, k, brr, d3, x%
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Set d3 = CreateObject("scripting.dictionary")
i = [b65536].End(3).Row
For m = 2 To i
If Not d1.exists(Cells(m, 2).Value) Then
d1(Cells(m, 2).Value) = 1
Else
d1(Cells(m, 2).Value) = d1(Cells(m, 2).Value) + 1
End If
If Not d2.exists(Cells(m, 2).Value) Then
d2(Cells(m, 2).Value) = Cells(m, 3).Value
Else
d2(Cells(m, 2).Value) = d2(Cells(m, 2).Value) & "," & Cells(m, 3).Value
End If
Next
[e2].Resize(d1.Count, 1) = WorksheetFunction.Transpose(d1.keys)
[f2].Resize(d1.Count, 1) = WorksheetFunction.Transpose(d1.items)
For n = 2 To d1.Count + 1
brr = Split(d2(Cells(n, 5).Value), ",")
For x = 0 To UBound(brr)
If Not d3.exists(brr(x)) Then
d3(brr(x)) = ""
End If
Next
Cells(n, 7).Resize(1, d3.Count) = WorksheetFunction.Transpose(WorksheetFunction.Transpose(d3.keys))
Next
End Sub
|