|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("此表求和")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(3, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(1, c)
- For j = 2 To UBound(arr, 2)
- d1(arr(1, j)) = j
- Next
- End With
- ls = c
- With Worksheets("录入")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a4:z" & r)
- End With
- For i = 1 To UBound(arr)
- If d1.exists(arr(i, 11)) Then
- n = d1(arr(i, 11))
- If Not d.exists(arr(i, 20)) Then
- ReDim brr(1 To ls)
- brr(1) = arr(i, 20)
- Else
- brr = d(arr(i, 20))
- End If
- brr(n) = brr(n) + arr(i, 16)
- brr(n + 1) = brr(n + 1) + arr(i, 19)
- brr(2) = brr(2) + arr(i, 16)
- brr(3) = brr(3) + arr(i, 19)
- d(arr(i, 20)) = brr
- End If
- Next
- With Worksheets("此表求和")
- .Range("a4:bk51").ClearContents
- .Range("a4").Resize(d.Count, ls) = Application.Transpose(Application.Transpose(d.items))
- End With
- End Sub
复制代码 |
|