How do I sum rows until first blank row?

MikeMcCollister

Board Regular
Joined
May 6, 2020
Messages
78
Office Version
  1. 365
Platform
  1. Windows
I would like to sum rows in a table until the first blank row and then stop. I've tried

Excel Formula:
=SUM(TRIMRANGE(B2:$B$22))

but it keeps going to the end of the range. Any idea how to do that?

1740671703384.png


Note that I will only do this when the "Description" is set to "-Various-" but I wanted to keep it simple for this forum.

Thanks,

Mike
 
Hello, maybe something like:

Excel Formula:
=LET(
d,A2:A22,
v,B2:B22,
g,SCAN(0,--(d="-Various-"),LAMBDA(a,b,a+b)),
s,GROUPBY(g,v,SUM,,0),
IF((d<>"")*(v=""),XLOOKUP(g,INDEX(s,0,1),INDEX(s,0,2)),""))
 
Upvote 0
Another option
Fluff.xlsm
ABC
1
2-Various-10
31
42
53
64
7-Various-18
85
96
107
11-Various-17
128
139
14-Various-75
1510
1611
1712
1813
1914
2015
21
22
23Total120
Sheet6
Cell Formulas
RangeFormula
C2:C22C2=MAP(A2:A22,B2:B22,LAMBDA(x,y,IF(x="-various-",SUM(y:INDEX(y:B22,IFNA(XMATCH(x,INDEX(A:A,ROW(x)+1):A22),y))),"")))
B23B23=SUM(B2:B22)
Dynamic array formulas.
 
Upvote 0
Thanks for the inspiration. I have come up with a fairly simple formula:

Excel Formula:
=IF(A2="-Various-", SUM(B2:XLOOKUP(, B3:B$22, B3:B$22)), "")

It just fails if the last group of numbers does not have a blank cell at B22 or above. I'll play around some more to see if there is something more elegant.

1740681027102.png
 
Upvote 0
I added the B$22 to XLOOKUP so that it will work if the list goes to the end.

Excel Formula:
=IF(A2="-Various-", SUM(B2:XLOOKUP(, B3:B$22, B3:B$22, B$22)), "")

1740681461289.png
 
Upvote 0
Solution
Glad you sorted it & thanks for the feedback.
 
Upvote 0

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