How do I sum consecutive rows that meet a criteria?

shimmer

New Member
Joined
Aug 29, 2013
Messages
3
In the table below the first column is my data, the second is what I want to use a formula to do, I just put these values in by hand. Any ideas would be really appreciated.
[TABLE="width: 168"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD="align: center"]What I have[/TD]
[TD="align: center"] What I want a formula to do[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]4[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]6[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]4[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
you need to tell us what you want to do - it starts out looking like you are summing up to 3 consecutive numbers but then changes. Are you just counting all consecutive 1's ?
 
Upvote 0
Hi
Thanks for replying. Yes I'm trying to add up consecutive 1's.

If the data consists of just 0's and 1's and you want to add up each consecutive 1 in-between 0's...

[TABLE="width: 96"]
<colgroup><col style="width: 48pt;" span="2" width="64"> <tbody>[TR]
[TD="class: xl63, width: 64, bgcolor: transparent"]X[/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"]Y[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]2[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]3[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]4[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]5[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]6[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]0[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]2[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]3[/TD]
[/TR]
[TR]
[TD="class: xl64, width: 64, bgcolor: white"]1[/TD]
[TD="class: xl64, width: 64, bgcolor: white"]4[/TD]
[/TR]
</tbody>[/TABLE]

B2, jsut enter and copy down:
Rich (BB code):
=IF(A2=0,0,IFERROR(SUM(INDEX($A$1:A1,LOOKUP(9.99999999999999E+307,1/($A$1:A1=0),
  ROW($A$1:A1)-ROW($A$1)+1)):A2),0))
 
Upvote 0
another way with a shorter formula

[TABLE="width: 192"]
<colgroup><col span="3"></colgroup><tbody>[TR]
[TD]X[/TD]
[TD]Y[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]6[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]4[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]formula in B2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"]=IF(A2=0,0,IF(A1=1,1+B1,1))[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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