|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 分类汇总()
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("流水账")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "流水账为空!": End
ar = .Range("a1:e" & r)
End With
Dim br()
ReDim br(1 To UBound(ar), 1 To 4)
For i = 2 To UBound(ar)
If ar(i, 2) <> "" Then
zd = ar(i, 2) & "|" & ar(i, 3)
t = d(zd)
If t = "" Then
k = k + 1
d(zd) = k
t = k
br(k, 1) = k
br(k, 2) = ar(i, 2)
br(k, 3) = ar(i, 3)
End If
br(t, 4) = br(t, 4) + ar(i, 4)
End If
Next i
With Sheets("实时统计")
.[a1].CurrentRegion.Offset(1) = Empty
.[a2].Resize(k, UBound(br, 2)) = br
End With
MsgBox "ok!"
End Sub
|
|