Calculations based on consecutive rows

GLIBBY

New Member
Joined
Jun 14, 2010
Messages
37
Hello all. Im wondering how I can do calculations on a column of cells, based on reference column having consecutive values. Say I have the following

A|B
-----
5|1
5|1
5|1
6|1
3|1
2|1
5|1
5|1
5|1

I want to have one cell (say C1) contain the sum of the first block of values in column B, that corresponds with the first block of consecutive 5s in column A. Then I'd have another cell (C2) contain the sum of the values in column B that corresponded with the second block of consecutive 5s, and so on for the entire spreadsheet.

Basically as soon as there is a break from a certain value (5 in this case) in a column I want a new calculation to be performed, for a different cell, on the next set of data that corresponds with consecutive values.

Does that make any sense? Thanks!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hello all. Im wondering how I can do calculations on a column of cells, based on reference column having consecutive values. Say I have the following

A|B
-----
5|1
5|1
5|1
6|1
3|1
2|1
5|1
5|1
5|1

I want to have one cell (say C1) contain the sum of the first block of values in column B, that corresponds with the first block of consecutive 5s in column A. Then I'd have another cell (C2) contain the sum of the values in column B that corresponded with the second block of consecutive 5s, and so on for the entire spreadsheet.

Basically as soon as there is a break from a certain value (5 in this case) in a column I want a new calculation to be performed, for a different cell, on the next set of data that corresponds with consecutive values.

Does that make any sense? Thanks!
Is this what you want:

Book1
ABC
251_
351_
4513
561_
631_
721_
851_
951_
1051_
11514
1211_
13511
1421_
1551_
16512
1731_
1851_
1951_
2051_
21514
Sheet1
 
Upvote 0
Yes exactly. The one thing I failed to mention it my initial post is that I wont always know where the consecutive blocks are, since they depend on another function. However, they will always be in the same column.
 
Upvote 0
Yes exactly. The one thing I failed to mention it my initial post is that I wont always know where the consecutive blocks are, since they depend on another function. However, they will always be in the same column.
OK, based on the sample I posted in the other reply...

Enter this formula in C2:

=IF(AND(A2=5,A3=5),"",IF(A2=5,B2,""))

Enter this formula in C3 and copy down to the end of data:

=IF(AND(A3=5,A4<>5),SUMIF(A$2:A3,5,B$2:B3)-SUM(C$2:C2),"")
 
Upvote 0
Im realizing that what I need to implement is harder, and has a different approach from what I was describing earlier.

Its the same set-up with random blocks of consecutive data, but I want the result cell to be a subtraction between the first and last cell of a block. so if I have:

A|B
----
4|1
5|10
5|5
5|5
5|1
3|1

I'd expect the result of 9. Im having trouble wrapping my brain around "finding" the first and last consecutive entries. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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