Sub byPeteryhr()
Dim i&, j&, jsNum&, s$, arr, brr(), Dic As Object
Set Dic = CreateObject("Scripting.Dictionary")
Dic.Add "A", 4: Dic.Add "B", 5: Dic.Add "C", 6
With Sheet1
.Range("H1:M" & Cells(Rows.Count, "H").End(xlUp).Row).Offset(1).ClearContents
arr = [A1].CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 6)
For i = 2 To UBound(arr)
s = arr(i, 2) & "," & arr(i, 3) & "," & arr(i, 4)
If arr(i, 4) <> 4 Then
If Dic.exists(s) Then
brr(Dic(s), Dic(arr(i, 5))) = brr(Dic(s), Dic(arr(i, 5))) + arr(i, 6)
Else
jsNum = jsNum + 1
For j = 1 To 3
brr(jsNum, j) = arr(i, j + 1)
Next
brr(jsNum, Dic(arr(i, 5))) = arr(i, 6)
Dic(s) = jsNum
End If
End If
Next
[H2].Resize(UBound(brr), UBound(brr, 2)) = brr
End With
Set Dic = Nothing
End Sub
|