|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 分类汇总()
Dim ar As Variant
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Worksheets("基础数据")
r = .Cells(.Rows.Count, 2).End(xlUp).Row
ar = .Range("a1:n" & r)
End With
ReDim br(1 To UBound(ar), 1 To 14)
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
zf = Trim(ar(i, 2)) & "|" & Trim(ar(i, 3)) & "|" & Trim(ar(i, 4)) & "|" & Trim(ar(i, 5))
t = d(zf)
If t = "" Then
k = k + 1
d(zf) = k
t = k
br(k, 1) = k
For j = 2 To 5
br(k, j) = ar(i, j)
Next j
End If
For j = 12 To 14
br(t, j) = br(t, j) + ar(i, j)
Next j
End If
Next i
With Worksheets("汇总表")
.UsedRange.Offset(1).Clear
.Range("a2").Resize(k, UBound(br, 2)) = br
.Range("a2").Resize(k, UBound(br, 2)).Borders.LineStyle = 1
End With
MsgBox "ok!"
End Sub
|
|