供参考。。。。
Sub test000()
Set d = CreateObject("scripting.dictionary")
arr = [c2].CurrentRegion
For i = 2 To UBound(arr)
If Not d.exists(arr(i, 1)) Then
d(arr(i, 1)) = Array(arr(i, 2), arr(i, 3), arr(i, 4), arr(i, 2) + arr(i, 3) + arr(i, 4))
Else
d(arr(i, 1)) = Array(d(arr(i, 1))(0) + arr(i, 2), d(arr(i, 1))(1) + arr(i, 3), d(arr(i, 1))(2) + arr(i, 4), d(arr(i, 1))(3) + arr(i, 2) + arr(i, 3) + arr(i, 4))
End If
Next
ReDim brr(1 To d.Count + 1, 1 To 5)
For Each Key In d.keys
m = m + 1
brr(m, 1) = Key
brr(d.Count + 1, 1) = "合计"
For j = 2 To 5
brr(m, j) = d(Key)(j - 2)
brr(d.Count + 1, j) = brr(d.Count + 1, j) + d(Key)(j - 2)
Next
Next
[h3].Resize(UBound(brr), UBound(brr, 2)) = brr
End Sub
|