Summarizing doubles

  • Thread starter Thread starter Sippan
  • Start date Start date
S

Sippan

I have a rather lengthy list of products sold by the company I work for; one
column with the product name, one column with the number of articles sold.
There are many instances where the same product appears on several rows. I am
looking for a way to remove the doubles in the first column, but summarize
the different values in the second column into one. How?
 
Sub TidyUp()
Dim LastRow As Long
Dim pos As Long
Dim i As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 3 Step -1

pos = 0
On Error Resume Next
pos = Application.Match(.Cells(i, "A").Value,
..Range("A1").Resize(i - 1), 0)
On Error GoTo 0
If pos > 0 Then

.Cells(pos, "B").Value = .Cells(pos, "B").Value + .Cells(i,
"B").Value
.Rows(i).Delete
End If
Next i
End With
End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top