|
Sub test()
Dim i As Integer, arr, BRR(), dic As Object, dic1 As Object, j As Byte
Set dic = CreateObject("scripting.dictionary")
Set dic1 = CreateObject("scripting.dictionary")
arr = Sheets(2).[A1].CurrentRegion
For i = 2 To UBound(arr)
If arr(i, 1) <> "" Then
dic1(arr(i, 1)) = ""
End If
dic(arr(i, 1) & arr(i, 3)) = dic(arr(i, 1) & arr(i, 3)) + arr(i, 2)
Next i
Key = dic1.KEYS
Sheets(1).[A2].Resize(dic1.Count, 1) = WorksheetFunction.Transpose(Key)
arr = Sheets(1).[A1].CurrentRegion
L = Cells(1, Columns.Count).End(xlToLeft).Column
ReDim BRR(1 To dic1.Count, 1 To L - 2)
For i = 1 To UBound(BRR)
For j = 1 To UBound(BRR, 2)
BRR(i, j) = dic(arr(i + 1, 1) & arr(1, j + 2))
Next j
Next i
[c2].Resize(UBound(BRR), L - 2) = BRR
Set dic = Nothing
[A1].CurrentRegion.EntireColumn.AutoFit
[A1].CurrentRegion.Borders.LineStyle = xlContinuous
End Sub |
|