PDA

View Full Version : Grouping



techem
10-07-2008, 05:34 AM
Hello,

I really really need help fast here.

I have 2 columns like this:

ID Number
1 22
1 5
1 0
1 8
44 30
44 45
56 2
56 5
56 7

I'm trying code so that the result will be:
ID Sum
1 35
44 75
56 14

How do I do that? Help would really be appreciated! :help

Thank you very much for your time!

Bob Phillips
10-07-2008, 05:47 AM
Public Sub ProcessData()
Dim i As Long
Dim LastRow As Long
Dim Running As Double

With Application

.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

With ActiveSheet

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

If .Cells(i, "A").Value = .Cells(i - 1, "A").Value Then

Running = Running + .Cells(i, "B").Value
.Rows(i).Delete
Else

.Cells(i, "B").Value = .Cells(i, "B").Value + Running
Running = 0
End If
Next i
End With

With Application

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub

techem
10-07-2008, 05:59 AM
THANK YOU VERY VERY MUCH!!!