|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 汇总()
- Range("A5:V10000").ClearContents
- Dim m, n, i, j, arr, brr, ar, br(), cr()
- Dim d As Object, da As Object, k, kk, t, tt
- Set d = CreateObject("scripting.dictionary")
- Set da = CreateObject("scripting.dictionary")
- ar = Range("C4:U4")
- For i = 1 To UBound(ar, 2): da(ar(1, i)) = i: Next
- arr = Sheet1.Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 3)) Then
- m = 1: ReDim brr(1 To 22, 1 To m)
- Else
- brr = d(arr(i, 3)): m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 22, 1 To m)
- End If
- If da.exists(arr(i, 4)) Then brr(da(arr(i, 4)) + 2, m) = arr(i, 10)
- d(arr(i, 3)) = brr
- Next
- k = d.keys: t = d.items
- For x = 0 To d.Count - 1
- For i = 1 To UBound(t(x), 2)
- n = n + 1: ReDim Preserve br(1 To 22, 1 To n)
- br(1, n) = k(x)
- For j = 2 To 22: br(j, n) = t(x)(j, i): Next
- Next
- Next
- m = 0: d.RemoveAll
- arr = Sheet2.UsedRange
- For i = 1 To UBound(br, 2)
- s = br(1, i)
- If d(s) = "" Then
- m = m + 1: ReDim Preserve cr(1 To 22, 1 To m)
- d(s) = m: cr(1, m) = s
- For j = 3 To 21: cr(j, m) = br(j, i): Next
- Else
- For j = 3 To 21: cr(j, d(s)) = cr(j, d(s)) + br(j, i): Next
- End If
- For j = 2 To UBound(arr)
- If cr(1, m) = arr(j, 1) Then cr(22, m) = arr(j, 2)
- Next
- Next
- For i = 1 To m
- For j = 3 To 22: cr(2, i) = cr(2, i) + cr(j, i): Next
- Next
- [A5].Resize(m, 22) = Application.Transpose(cr)
- Set d = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|