I have a spreadsheet with duplicate data in column 1 (Names of Customers). Each row contains the name of a customer and a record of their purchases, including a column for amounts. I have a VBA macro to eliminate the duplicate rows based on the names in Column 1 (see below). However, I want to consolidate the total purchases so that I end up with 1 row per customer and the total dollar value of their purchases in the cell for Amounts.
VBA:
Public Sub DeleteDuplicateRows()
'
'This macro deletes duplicate rows in the selection. Duplicates are
'counted in the COLUMN of the active cell.
Dim Col As Integer
Dim r As Long
Dim C As Range
Dim N As Long
Dim V As Variant
Dim Rng As Range
On Error Goto EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Col = ActiveCell.Column
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
N = 0
For r = Rng.Rows.Count To 1 Step -1
V = Rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(Rng.Columns(1), V) > 1 Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If
Next r
EndMacro:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Bookmarks