|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
分类汇总。。。
- Sub ykcbf() '//2024.7.11 分类汇总
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- With Sheets("Sheet1")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 7)
- End With
- ReDim brr(1 To UBound(arr), 1 To 9)
- b = [{2,3,5}]
- For j = 1 To UBound(b)
- d.RemoveAll
- m = 0
- n = n + 3
- For i = 3 To UBound(arr)
- s = arr(i, b(j))
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, n - 2) = s
- brr(m, n - 1) = 1
- brr(m, n) = arr(i, 6)
- Else
- r = d(s)
- brr(r, n - 1) = brr(r, n - 1) + 1
- brr(r, n) = brr(r, n) + arr(i, 6)
- End If
- Next
- Max = IIf(Max < m, m, Max)
- Next
- With Sheets("Sheet2")
- .UsedRange.Offset(1).Clear
- .[a1].Resize(1, 9).Interior.Color = 49407
- With .[a2].Resize(Max + 1, 9)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- r = Max + 1
- For j = 2 To 9
- .Cells(r + 1, j) = Application.Sum(.Cells(2, j).Resize(Max))
- Next
- For j = 1 To 7 Step 3
- .Cells(r + 1, j) = "合计"
- Next
- .Cells(r + 1, 1).Resize(, 9).Interior.ColorIndex = 6
- ActiveWindow.DisplayZeros = False
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|