|
- Sub test()
- Dim d As New Dictionary
- Dim d1 As New Dictionary
- Dim r%, i%
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:c" & r)
- End With
- For i = 1 To UBound(arr)
- d1(arr(i, 1)) = ""
- If Not d.Exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 2))(arr(i, 1)) = d(arr(i, 2))(arr(i, 1)) + arr(i, 3)
- Next
- With Worksheets("sheet2")
- .UsedRange.Offset(1, 0).ClearContents
- For Each aa In d.Keys
- r0 = .Cells(.Rows.Count, 4).End(xlUp).Row + 1
- .Cells(r0, 4).Resize(d(aa).Count, 1) = Application.Transpose(d(aa).Keys)
- .Cells(r0, 5).Resize(d(aa).Count, 1) = Application.Transpose(d(aa).Items)
- r1 = .Cells(.Rows.Count, 4).End(xlUp).Row
- .Range(.Cells(r0, 3), .Cells(r1, 3)) = aa
- Next
- End With
- With Worksheets("sheet3")
- .UsedRange.Offset(1, 0).ClearContents
- .Range("a2").Resize(d1.Count, 1) = Application.Transpose(d1.Keys)
- End With
- End Sub
复制代码 |
|