Identifying rows that sum up to the largest total

bbibo

New Member
Joined
Aug 4, 2014
Messages
4
Row #Value
1385
2-732
3244
4457
5436

<tbody>
</tbody>
Is there a formula in excel that would identify the consecutive values that yield the highest sum ? In this simple example adding rows 3 to 5 will give you the highest total which is 1,137.

I have a list of nearly 1,000 rows and I'll need a formula to identify which consecutive rows should be added to arrive at the highest sum total.

Thanks !
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
No, it can be 3 rows or 1,000 rows - the number of rows is not a condition. The condition is that the rows are consecutive and their sum total generates the highest sum
 
Upvote 0
Control+shift+enter, not just enter:

=MAX(SUBTOTAL(9,OFFSET(B1,ROW(B1:B5)-ROW(B1)+1,0,3)))

Is this what you are after?

Or is it?

=MAX(SUBTOTAL(9,OFFSET(B1,ROW(B1:B5)-ROW(B1),0,ROW(INDIRECT("1:"&ROWS(B1:B5))))))
 
Last edited:
Upvote 0
Thanks a lot for your post Aladin. I guess your first formula limits it to 3 consecutive rows which is not the case here.

I guess your second formula is more relevant in my case, however please refer to the attached file on this link: FileSwap.com : Excel problem.xlsx download free

I am arriving at a value of 9,738 although I can see that If I manually add cells B1:B131 I can get 10,265... Please take a look.

Thanks a lot !!
 
Upvote 0
Hi,

I haven't downloaded your attachment, but if I understand you, then first go to Name Manager and define the following:

Name: Range1
Refers to: =$A$1:$A$5

(Or whatever the range in question happens to be.)

Name: Arry1
Refers to: =ROW(INDIRECT("1:"&ROWS(Range1)))

Exit Name Manager.

Enter this array formula** in B1:

=MIN(IF(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)=MAX(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)),TRANSPOSE(Arry1)))


Then this array formula** in C1:

=IF(ROWS($1:1)>$B$1,"",INDEX(Range1,MIN(IF(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)=MAX(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)),Arry1))+ROWS($1:1)-1))


Copy this formula down (though not the one in B1) until you start to get blanks for the results.

Note that I have added a small qualifier to this formula to differentiate cases where there are actually more than one consecutive stringa in the range which share the maximum value. You didn't mention which should be preferred in this case: my solution will give the first it finds within the range.

Regards


**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
</SPAN></SPAN>
 
Upvote 0
Hi,

I haven't downloaded your attachment, but if I understand you, then first go to Name Manager and define the following:

Name: Range1
Refers to: =$A$1:$A$5

(Or whatever the range in question happens to be.)

Name: Arry1
Refers to: =ROW(INDIRECT("1:"&ROWS(Range1)))

Exit Name Manager.

Enter this array formula** in B1:

=MIN(IF(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)=MAX(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)),TRANSPOSE(Arry1)))


Then this array formula** in C1:

=IF(ROWS($1:1)>$B$1,"",INDEX(Range1,MIN(IF(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)=MAX(SUBTOTAL(9,OFFSET(INDEX(Range1,1,1),Arry1-1,,TRANSPOSE(Arry1),))+1/(Arry1*10^9)),Arry1))+ROWS($1:1)-1))


Copy this formula down (though not the one in B1) until you start to get blanks for the results.

Note that I have added a small qualifier to this formula to differentiate cases where there are actually more than one consecutive stringa in the range which share the maximum value. You didn't mention which should be preferred in this case: my solution will give the first it finds within the range.

Regards


**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

Thank You very much !
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

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