|
Sub 分类汇总()
Set dic = CreateObject("scripting.dictionary")
Dim brr()
arr = Sheets("sheet1").[a1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 10)
For i = 2 To UBound(arr)
ms = arr(i, 2) & arr(i, 3)
If Not dic.exists(ms) Then
x = x + 1
dic(ms) = x
For j = 1 To 5
brr(x, 1) = arr(i, j)
Next j
Else
brr(dic(ms), 1) = brr(dic(ms), 1) & "," & arr(i, 1)
brr(dic(ms), 5) = brr(dic(ms), 5) + arr(i, 5)
End If
Next i
With Sheets("sheet2")
.Cells.ClearContents
Sheets("sheet1").[a1].Resize(1, 5).Copy .[a1]
.Columns(1).NumberFormatLocal = "@"
.[a2].Resize(dic.Count, 5) = brr
End With
Set dic = Nothing
End Sub |
|