How to remove duplicates and combine their unique values?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi again!

I have a list which contains duplicates and values attached to every entry.
Like this:

col a col b
0 5
0 11
1 7
2 5
....

And I would like to make the list look like this:

col a col b
0 16
1 12
....

So, how to do this? Please I need your help!
-Dave
 
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
Dim cell As Range
Dim sh As Worksheet

With ActiveSheet

Application.ScreenUpdating = False

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If .Cells(i, "A").Value = .Cells(i - 1, "A").Value Then
.Cells(i - 1, "B").Value = .Cells(i - 1, "B").Value + _
.Cells(i, "B").Value
.Rows(i).Delete
End If
Next i

Application.ScreenUpdating = True

End With

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
On a new sheet, try Data > Consolidate, select the table reference
with the options "Sum" and labels in "Left Column" then click OK.
 
Back
Top