PDA

View Full Version : Solved: Macro adding cells together containing the same text



buhay
09-23-2010, 01:09 PM
I am trying to add cells togehter containing the same text in the preceding columns.

For example

------colA------colB

row1---ABC-------7

row2---ABC-------5

row3---ABC-------2

row4---EFG-------10

row5---EFG-------15

row6---EFG-------5

is supposed to look like this after using the macro

------colA------colB

row1---ABC-------14

row2---EFG-------20

Any help is appreciated

Imdabaum
09-23-2010, 02:21 PM
You can try this.

=SUMIF($A1:$Ax, "ABC", $B1:$Bx)

Bob Phillips
09-23-2010, 02:40 PM
Public Sub ProcessData()
Dim Lastrow As Long
Dim i As Long

Application.ScreenUpdating = False

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

.Cells(i - 1, "B").Value = .Cells(i - 1, "B").Value _
+ .Cells(i, "B").Value
.Rows(i).Delete
End If
Next i
End With

Application.ScreenUpdating = True
End Sub

buhay
09-23-2010, 02:50 PM
Both of you, thank you very much especially to you xld