Loop thru range within groupings not to exceed a sum of 90

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,364
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello and Happy New Year too all,

I have a range of cells that in column R are the count of number of words in column Q by row. I did not post the contents of column Q because they are not so much in the question. In column S, I now have the cumulative total starting from R2. Once the cumulative total in column S is less than or equal to 90, that would be the first group in the loop. The next loop would start in R7 and count until the cumulative total is less than or equal to 90. And so on.

With the set of data, I would expect 11 grouping, or the loop to process 11 times. How can I achieve this loop, of is there a formula I can use in column S to get me the highest number in each grouping less than 90. Basically, what I'm doing, column Q has some text that I'm transferring over to ppt. I have all of that working, but right now it's static to just doing every three rows. I would like to make it dynamic to select any number of rows but not greater than 90. I hope this make sense.

R2:R6 = 90
R7:R9 = 67
R10:R12 = 79
R13:R15 = 76
R16:R19 = 90
and so on...

1111
2940
1252
1668
2290
24114
26140
17157
25182
23205
31236
30266
11277
35312
23335
27362
16378
24402
11413
27440
35475
23498
11509
30539
34573
51624
22646
45691
36727
39766
25791
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello and happy new year to you too.

Check if this result is what you need:

Dante Amor
AQRS
1CountGroup
211 
329 
412 
516 
62290
724 
826 
91767
1025 
1123 
123179
1330 
1411 
153576
1623 
1727 
1816 
192490
2011 
2127 
223573
2323 
2411 
253064
2634 
275185
2822 
294567
3036 
313975
322525
Hoja3
Cell Formulas
RangeFormula
S2:S32S2=IF(R3="",R2,IF(SUM($R$2:R3)-SUM($S$1:S1)<=90,"",SUM($R$2:R2)-SUM($S$1:S1)))
 
Upvote 0
Hi Dante and thanks a lot for the help,

Now I need to get a number I can use to build the resize component. As you can see in column T, I started to work on a formula, but the results should be as in column U.

CountGroupResize
11
29
12
16
229055
24
26
176783
25
23
3179113
30
11
3576143
23
27
16
2490184
11
27
3573213
23
11
3064243
34
5185262
22
4567282
36
3975302
2525311
 
Upvote 0
Hi Dante, Here is what I've come up with.

U2 and Down -- =IF(N(S2),COUNT($R$2:R2)-MAX($T$1:T1),"")

Not sure if there is a way to combine column T and U into one

T2 and Down -- =IF(N(S2),COUNT($R$2:R2)-T1,"")

CountGroupResize
11
29
12
16
229055
24
26
176783
25
23
3179113
30
11
3576143
23
27
16
2490184
11
27
3573213
23
11
3064243
34
5185262
22
4567282
36
3975302
2525311
 
Upvote 0
Try this:

Dante Amor
AQRST
1CountGroupResize
211  
329  
412  
516  
622905
724  
826  
917673
1025  
1123  
1231793
1330  
1411  
1535763
1623  
1727  
1816  
1924904
2011  
2127  
2235733
2323  
2411  
2530643
2634  
2751852
2822  
2945672
3036  
3139752
3225251
Hoja3
Cell Formulas
RangeFormula
S2:S32S2=IF(R3="",R2,IF(SUM($R$2:R3)-SUM($S$1:S1)<=90,"",SUM($R$2:R2)-SUM($S$1:S1)))
T2:T32T2=IF(R3="",COUNT($R$2:R2)-SUM($T$1:T1),IF(SUM($R$2:R3)-SUM($S$1:S1)<=90,"",COUNT($R$2:R2)-SUM($T$1:T1)))
 
Upvote 0
Upvote 0
That is absolutely perfect. Thank you!
Just checking ..
I have altered one of the column R values (yellow cell). Doesn't that make the orange cell incorrect? Perhaps I have not understood properly but I was thinking that the final row value should then be 81 per the modified formula in column T?

23 01 03.xlsm
RST
1CountGroupGroup
211  
329  
412  
516  
6229090
724  
826  
9176767
1025  
1123  
12317979
1330  
1411  
15357676
1623  
1727  
1816  
19249090
2011  
2127  
22357373
2323  
2411  
25306464
2634  
27518585
2822  
29456767
3036  
3120  
32252581
Groups
Cell Formulas
RangeFormula
S2:S32S2=IF(R3="",R2,IF(SUM($R$2:R3)-SUM($S$1:S1)<=90,"",SUM($R$2:R2)-SUM($S$1:S1)))
T2:T32T2=IF(OR(SUM($R$2:R3)-SUM($T$1:T1)>90,R3=""),SUM($R$2:R2)-SUM($T$1:T1),"")
 
Upvote 0
Solution
Hi Peter, yes, after some testing, that is correct. Your new updated formula caught it. Thanks.
 
Upvote 0
You're welcome. Thanks for the confirmation. :)
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,026
Members
449,061
Latest member
TheRealJoaquin

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