|
每个人写代码的思路不一样,如果看你的代码,我觉得比较累,还是自己写比较好,代码如下:
- Sub test()
- Dim arr, i%, d, rng As Range, c
- Set d = CreateObject("scripting.dictionary")
- arr = Range("A1").CurrentRegion
- [e2:G1048576].ClearContents
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- d(arr(i, 1))(arr(i, 2)) = d(arr(i, 1))(arr(i, 2)) + arr(i, 3)
- Next
- For Each c In d.keys
- Set rng = Range("F1048576").End(3).Offset(1)
- rng.Resize(d(c).Count, 2) = Application.Transpose(Array(d(c).keys, d(c).items))
- rng.Resize(d(c).Count, 1).Offset(0, -1) = c
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|