|
Sub 分类汇总()
Application.ScreenUpdating = False
Dim d As Object
Dim ar As Variant, br As Variant
Dim i As Long
Dim arr()
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:f" & r)
ReDim arr(1 To UBound(ar), 1 To 4)
For i = 2 To UBound(ar)
If Trim(ar(i, 3)) <> "" And Trim(ar(i, 4)) <> "" Then
zf = Trim(ar(i, 3)) & "|" & Trim(ar(i, 4))
t = d(zf)
If t = "" Then
k = k + 1
d(zf) = k
t = k
arr(k, 1) = ar(i, 3)
arr(k, 2) = ar(i, 4)
End If
arr(t, 3) = arr(t, 3) + ar(i, 5)
If arr(t, 4) = "" Then
arr(t, 4) = ar(i, 6)
Else
arr(t, 4) = arr(t, 4) & ";" & ar(i, 6)
End If
End If
Next i
rs = .Cells(Rows.Count, 8).End(xlUp).Row
If rs > 1 Then .Range("h2:k" & rs) = Empty
.[h2].Resize(k, 4) = arr
End With
MsgBox "Ok!"
End Sub
|
|