.
Sub SummarizeData()Dim LR As Long, BR As Long
With ActiveSheet
BR = .Range("G" & .Rows.Count).End(xlUp).Row
If BR > 1 Then .Range("G1").CurrentRegion.ClearContents
LR = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A1:C" & LR).Copy .Range("G1")
BR = .Range("G" & .Rows.Count).End(xlUp).Row
.Range("G1:I" & BR).RemoveDuplicates Columns:=Array(1, 3), Header:=xlYes
BR = .Range("G" & .Rows.Count).End(xlUp).Row
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range("G2:G" & BR), Order:=xlAscending
.Sort.SortFields.Add Key:=Range("I2:I" & BR), Order:=xlAscending
With .Sort
.SetRange Range("G1:I" & BR)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
.Range("H2:H" & BR).FormulaR1C1 = "=MIN(8, SUMIFS(R2C2:R16C2, R2C1:R16C1,RC[-1], R2C3:R16C3,RC[1]))"
End With
End Sub