|
Sub 分类汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
ReDim arr(1 To 100000, 1 To 5)
For Each sh In Worksheets
If sh.Name <> "汇总" Then
ar = sh.[a1].CurrentRegion
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
If Trim(ar(i, 1)) <> "合计" Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
arr(k, 1) = k
arr(k, 2) = ar(i, 1)
arr(k, 3) = ar(i, 2)
End If
arr(t, 4) = arr(t, 4) + ar(i, 4)
arr(t, 5) = arr(t, 5) + ar(i, 9)
End If
End If
Next i
End If
Next sh
With Sheets("汇总")
r = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("a3:e" & r + 1).Borders.LineStyle = 0
.Range("a3:e" & r + 1) = Empty
.[a3].Resize(k, UBound(arr, 2)) = arr
.[a3].Resize(k, UBound(arr, 2)).Borders.LineStyle = 1
End With
MsgBox "ok!"
End Sub
|
|