|
Sub test1()
Set d = CreateObject("Scripting.Dictionary")
[O1].CurrentRegion.ClearContents
arr = [A1].CurrentRegion
For i = 2 To UBound(arr)
s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3)
d(s) = d(s) + arr(i, 4)
Next
'--------------------------------
[O1:R1].Value = [A1:D1].Value
t1 = d.keys: t2 = d.items
[O2].Resize(UBound(t1) + 1) = Application.Transpose(t1)
[R2].Resize(UBound(t1) + 1) = Application.Transpose(t2)
'--------------------------------
brr = [O1].CurrentRegion
For i = 2 To UBound(brr)
x = Split(brr(i, 1), "|")
brr(i, 1) = x(0): brr(i, 2) = x(1): brr(i, 3) = x(2)
brr(i, 4) = Round(brr(i, 4), 0)
Next
[O1].Resize(UBound(brr), UBound(brr, 2)) = brr
'--------------------------------
[O1].CurrentRegion.Sort key1:=[O1], order1:=1, header:=xlYes
End Sub
|
|