|
Sub 分类汇总()
Dim ar As Variant
Dim d As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
With ActiveSheet
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "数据源为空!": End
ar = .Range("a1:c" & r)
ReDim br(1 To 100, 1 To 500)
br(1, 1) = "区域"
y = 1: k = 1
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
t = d(ar(i, 2))
If t = "" Then
k = k + 1
d(ar(i, 2)) = k
t = k
br(k, 1) = ar(i, 2)
End If
lh = d(ar(i, 1))
If lh = "" Then
y = y + 1
d(ar(i, 1)) = y
lh = y
br(1, y) = ar(i, 1)
End If
br(t, lh) = br(t, lh) + ar(i, 3)
End If
Next i
.[h1].CurrentRegion.Borders.LineStyle = 0
.[h1].CurrentRegion = Empty
.[h1].Resize(k, y) = br
.[h1].Resize(k, y).Borders.LineStyle = 1
End With
MsgBox "ok!"
End Sub
|
|