I have an excel sheet with 2 columns and can have upto 15K rows. I need to sum values, group by first and second column. Currently I am using the followinn macro, the code is copying the data across a new sheet, sorting it and removing the duplicates while adding the count if a match found. I have tested it for 500 rows items to so far and it takes couple of minutes and I am worried of the time taken if there are more rows (as there can be up to 15K rows).
Sub consolidateData()
Dim lRow As Long
Dim ItemRow1, ItemRow2 As String
Dim lengthRow1, lengthRow2 As String
Columns("A:C").Select
Selection.Copy
Sheets("Sheet3").Select
Range("A1").Select
ActiveSheet.Paste
Cells.Select
Selection.Sort _
Key1:=Range("A2"), Order1:=xlAscending, _
Key2:=Range("C2"), Order2:=xlDescending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
lRow = 2
Do While (Cells(lRow, 1) <> "")
ItemRow1 = Cells(lRow, "A")
ItemRow2 = Cells(lRow + 1, "A")
lengthRow1 = Cells(lRow, "C")
lengthRow2 = Cells(lRow + 1, "C")
If ((ItemRow1 = ItemRow2) And (lengthRow1 = lengthRow2)) Then
Cells(lRow, "B") = Cells(lRow, "B") + Cells(lRow + 1, "B")
Rows(lRow + 1).Delete
Else
lRow = lRow + 1
End If
Loop
End Sub
Could you please suggest if there is a quickest way to do it. Thanks in Advance.