Option Explicit
Sub TEST6()
Dim ar, i&, j&, r&, dic As Object, iPosRow&
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
ar = .Value
ReDim Preserve ar(1 To UBound(ar), 1 To UBound(ar, 2) + 1)
r = 1
For i = 2 To UBound(ar)
If Cells(i, 1).Interior.ColorIndex <> -4142 Then
If Not dic.exists(ar(i, 2)) Then
r = r + 1
For j = 1 To UBound(ar, 2)
ar(r, j) = ar(i, j)
Next j
ar(r, UBound(ar, 2)) = 1
dic(ar(i, 2)) = r
Else
iPosRow = dic(ar(i, 2))
ar(iPosRow, 4) = ar(iPosRow, 4) + ar(i, 4)
ar(iPosRow, UBound(ar, 2)) = ar(iPosRow, UBound(ar, 2)) + 1
End If
End If
Next i
End With
For i = 2 To r
ar(i, 2) = ar(i, 2) & "(" & ar(i, UBound(ar, 2)) & ")"
Next i
Columns("H:L").Clear
With [H1].Resize(r, UBound(ar, 2) - 1)
.Value = ar
.Font.Size = 10
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|