|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 分类汇总()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long, rs As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet1")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 4 Then MsgBox "数据源为空!": End
ar = .Range("b3:w" & r)
End With
For i = 2 To UBound(ar)
If ar(i, 2) <> "" Then
s = ar(i, 2)
If Not d.exists(s) Then Set d(s) = CreateObject("scripting.dictionary")
d(s)(i) = ""
End If
Next i
With Sheet2
.UsedRange.Offset(3).Borders.LineStyle = 0
.UsedRange.Offset(3).Interior.ColorIndex = 0
.UsedRange.Offset(3).UnMerge
.UsedRange.Offset(3) = Empty
w = 15
For Each k In d.keys
n = 0: hj = 0
ReDim br(1 To d(k).Count, 1 To UBound(ar, 2))
For Each kk In d(k).keys
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(kk, j)
Next j
hj = hj + ar(kk, 19)
Next kk
rs = .Cells(Rows.Count, 2).End(xlUp).Row + 1
.Cells(rs, 2).Resize(n, UBound(br, 2)) = br
.Cells(rs, 2).Resize(n, UBound(br, 2)).Borders.LineStyle = 1
.Cells(rs, 23).Resize(n, 1).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.MergeCells = False
End With
Selection.Merge
.Cells(rs, 23) = hj
.Cells(rs, 2).Resize(n, UBound(br, 2)).Interior.ColorIndex = w
w = w + 1
Next k
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|