Loop and running total

  • Thread starter Thread starter LuisE
  • Start date Start date
L

LuisE

I need to loop from row 50 to 1, step -1. Addin the values in Col A is equal
as long as they are equal to the one above. How can i keep a running total
that adds the value in A every time it repeats?

Thanks in advance
 
Luis,

Use a worksheet function:

=SUMPRODUCT((A1:A49=A2:A50)*A2:A50)

or in a macro

Sub TotalCalA()
Dim i As Long
Dim TotalA As Double
For i = 50 to 2 Step -1
If Cells(i,1).Value = Cells(i-1,1).Value Then
TotalA = TotalA + Cells(i,1).Value
End if
Next i
Msgbox TotalA
End Sub

HTH,
Bernie
MS Excel MVP
 
Back
Top