Try with this faster macro (it will put data in range 'a2' replacing old data. Please indicate your first free column in the first row because this code need two free column where sum data:
Sub Macro1()
myFreeColumn = "H"
With Sheets("sheet1")
lastrow1 = .Cells(.Rows.Count, "a").End(xlUp).Row
.Range("A1:a" & lastrow1).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range(myFreeColumn & "1"), Unique:=True
myColNum = Columns(myFreeColumn).Column
lastrow2 = Cells(Rows.Count, myFreeColumn).End(xlUp).Row
.Cells(2, myFreeColumn).Offset(0, 1).Resize(lastrow2 - 1, 1).FormulaR1C1 = _
"=SUMIF(C[-" & myColNum & "],RC[-1],C[-" & myColNum - 1 & "])"
.Range(.Cells(2, myColNum), .Cells(lastrow2, myColNum + 1)).Copy
.Range(myFreeColumn & "2").PasteSpecial xlValues
.Range("A2:B" & lastrow1).ClearContents
.Range(.Cells(2, myColNum), .Cells(lastrow2, myColNum + 1)).Copy Destination:=.Range("a2")
.Columns(myFreeColumn).Delete
.Columns(myFreeColumn).Delete
.Range("a2").Select
End With
End Sub
Bookmarks