|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Dim Dic As Object, i%, j%, k%, arr, brr
brr = Sheet2.Range("a1").CurrentRegion.Value
Set Dic = CreateObject("scripting.dictionary")
arr = Sheet1.Range("a1").CurrentRegion.Value
For i = 2 To UBound(arr)
s = Val(arr(i, 7))
If Not Dic.exists(s) Then
Dic(s) = Array(1, Val(arr(i, 3)), Val(arr(i, 4)))
Else
Dic(s) = Array(Dic(s)(0) + 1, Dic(s)(1) + Val(arr(i, 3)), Dic(s)(2) + Val(arr(i, 4)))
End If
Next
For j = 2 To UBound(brr)
brr(j, 2) = Dic(brr(j, 1))(0)
brr(j, 3) = Dic(brr(j, 1))(1)
brr(j, 4) = Dic(brr(j, 1))(2)
Next
Sheet2.Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
Set Dic = Nothing
End Sub |
|