|
Sub huizong1()
Dim i, j, k, m
Dim nostr As String
Dim arr, brr, crr
Dim d1 As Object
Dim d2 As Object
Dim d3 As Object
Set d1 = CreateObject("scripting.dictionary")
Set d2 = CreateObject("scripting.dictionary")
Set d3 = CreateObject("scripting.dictionary")
Sheet1.Range("f6:h12").Clear
arr = Sheet1.[a1].CurrentRegion
For i = 2 To UBound(arr)
d1(arr(i, 2)) = d1(arr(i, 2)) + arr(i, 4)
d2(arr(i, 2) & "," & arr(i, 3)) = ""
Next
ReDim crr(1 To UBound(arr), 1 To 2)
For Each k In d2.keys
nostr = k
brr = Split(nostr, ",")
m = m + 1
crr(m, 1) = Split(nostr, ",")(0)
crr(m, 2) = Split(nostr, ",")(1)
If Not d3.exists(crr(m, 1)) Then
d3(crr(m, 1)) = crr(m, 2)
Else
d3(crr(m, 1)) = d3(crr(m, 1)) & "," & crr(m, 2)
End If
Next
Sheet1.[f1].Resize(1, 3).Copy Sheet1.[f6]
Sheet1.[f7].Resize(d1.Count, 1) = Application.WorksheetFunction.Transpose(d1.keys)
Sheet1.[h7].Resize(d1.Count, 1) = Application.WorksheetFunction.Transpose(d1.items)
Sheet1.[g7].Resize(d3.Count, 1) = Application.WorksheetFunction.Transpose(d3.items)
End Sub
供参考 |
|