Excel Macro to group by column & sum value
Solved/Closed
Related:
- Excel groupby sum
- Excel mod apk for pc - Download - Spreadsheets
- Number to words in excel - Guide
- Excel marksheet - Guide
- Dash becomes date on excel ✓ - Office Software Forum
- Kernel for excel - Download - Backup and recovery
1 response
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Mar 12, 2010 at 07:08 AM
Mar 12, 2010 at 07:08 AM
Try this
Assumption:
1. When you start macro, the sheet from where data is to be copied is the active sheet
2. An empty cell in column A indicate end of data
3. You want to paste to sheet3 (correct in macro if that is not the case)
Assumption:
1. When you start macro, the sheet from where data is to be copied is the active sheet
2. An empty cell in column A indicate end of data
3. You want to paste to sheet3 (correct in macro if that is not the case)
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
Mar 16, 2010 at 01:44 AM
Thanks very much. This is what I was after. It works.
Your help much appreciated.
Thanks again.
Cheers