|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 多条件汇总() '\\2024\9\6
- Dim arr, brr, i, j, sa, r, d
- Set d = CreateObject("scripting.dictionary")
- With Sheet1
- r = .Cells(Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- End With
- ReDim brr(1 To UBound(arr), 1 To 4)
- For i = 2 To UBound(arr)
- sa = arr(i, 2)
- If Not d.exists(sa) Then
- n = n + 1
- d(sa) = n
- brr(n, 1) = arr(i, 1)
- brr(n, 2) = arr(i, 2)
- brr(n, 3) = arr(i, 3)
- brr(n, 4) = 1
- Else
- m = d(sa)
- brr(m, 3) = brr(m, 3) + arr(i, 3)
- brr(m, 4) = brr(m, 4) + 1
- End If
- Next
- With Sheet2
- .Range("g2:j" & r).Clear
- .[g2].Resize(n, 4) = brr
- End With
- End Sub
复制代码 |
|