|
Sub 汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("明细表")
r = .Cells(Rows.Count, 2).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If r < 3 Then MsgBox "明细表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
ReDim arr(1 To UBound(ar), 1 To UBound(ar, 2))
k = 2
arr(1, 1) = ar(1, 1)
arr(2, 1) = ar(2, 1)
For j = 3 To UBound(ar, 2)
arr(1, j - 1) = ar(1, j)
arr(2, j - 1) = ar(2, j)
Next j
For i = 3 To UBound(ar)
If ar(i, 1) = "" Then ar(i, 1) = ar(i - 1, 1)
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
arr(k, 1) = ar(i, 1)
End If
For j = 3 To UBound(ar, 2)
arr(t, j - 1) = arr(t, j - 1) + ar(i, j)
Next j
Next i
With Sheets("汇总表")
.[a1].CurrentRegion = Empty
.[a1].Resize(k, UBound(arr, 2)) = arr
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|