VBA LOOP SUM CONSECUTIVE NUMBERS

weissihm

New Member
Joined
May 21, 2015
Messages
8
I have a spreadsheet that I need to sum column L, if column J data is consecutive. If the reference is consecutive, they were most likely on the same order and I need to know the total of the order to compare to another spreadsheet.

It would be nice if it went from A2 to the last column, but I can also input a range if needed.

Thanks

REFERENCE (COLUMN J)AMOUNT (COLUMN L)EXPECTED OUTCOME (COLUMN M)
4018684.494.49
4019007.51
40190120.0327.54
4022074.584.58
4024806565
40248410.0210.02
4024958.79
4024969.6518.44
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Code:
Sub rollingsum()

i = 1
rollsum = 0
Do Until Cells(i, 10) = ""
    rollsum = rollsum + Cells(i, 11)
    If Cells(i + 1, 10) <> Cells(i, 10) + 1 Then
        Cells(i, 12) = rollsum
        rollsum = 0
    End If

    i = i + 1
Loop
End Sub
 
Upvote 0
Code:
Sub rollingsum()

i = 1
rollsum = 0
Do Until Cells(i, 10) = ""
    rollsum = rollsum + Cells(i, 11)
    If Cells(i + 1, 10) <> Cells(i, 10) + 1 Then
        Cells(i, 12) = rollsum
        rollsum = 0
    End If

    i = i + 1
Loop
End Sub

Thank you for the quick response. That works perfectly.
 
Upvote 0

Forum statistics

Threads
1,216,732
Messages
6,132,409
Members
449,727
Latest member
Aby2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top