Sum values in column O until empty cell is reached whilst excluding "NO" values

jfin1ty

New Member
Joined
May 15, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Hoping someone can help me with this query.
I have a workbook I am working on that currently sums all the values in column "O" if the value on the same row in column "L" is "WP" or "BS" until an empty cell is reached.
I would like to expand upon this formula so that it still sums like I have mentioned above but will not include summing for any value in column "O" if the value on the same row in column AC is equal to NO. Is this possible?
I have made the start of the formula have some if, or, and, offset evaluations that are required for a plethora of reasons I'd rather not get into so really I'd imagine it would just be a tweak to the SUM formula part onwards?

Book1
ABCDEGHIJKLMNOPQRSTUVWXYZAAABAC
1T
2RG11.559SP000000WP2.705
3 WP0.960
4 WP1.945
5 WP0.634
6 WP0.480
7 WP2.555
8 SP000001BS1.220
9 BS1.060
10 
11RG12.154SP000002WP0.955
12 WP0.556
13 WP2.128
14 WP5.720
15 WP2.795
Sheet1
Cell Formulas
RangeFormula
G2:G15G2=IF(OR(H2<>"",D2<>""),IF(AND(O2<>"",OR(OFFSET(O2,-1,0)="",OFFSET(O2,-1,0)="T")),SUM(O2:INDEX(O2:$O$101,MATCH(TRUE,($O2:O$101=""),0))),""),"")
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Book1
GHIJKLMNOPQAC
210.925SP000000WP2.705
3 WP0.96
4 WP1.945
5 WP0.634NO
6 WP0.48
7 WP2.555
8 SP000001BS1.22
9 BS1.06
10 
1111.199SP000002WP0.955NO
12 WP0.556
13 WP2.128
14 WP5.72
15WP2.795
Sheet1
Cell Formulas
RangeFormula
G2:G14G2=IF(OR(O1="",O1="T"),SUMPRODUCT(SUMIFS($O2:$O$15,$AC2:$AC$15,"<>NO",$L2:$L$15,{"WP","BS"}))-SUM($G3:$G$15),"")
 
Upvote 0
I'm not quite sure how column H fits into it or the "T" in O1, but in any case I would be trying to avoid the volatile function OFFSET if possible.
Could we employ something like we did in another similar thread of yourd recently?

23 05 23.xlsm
DGHLOAC
1T
2RG6.32SP000000WP2.705
3 WP0.96NO
4 WP1.945NO
5 WP0.634NO
6 WP0.48NO
7 WP2.555
8 SP000001BS1.22NO
9 BS1.06
10 
11RG7.848SP000002WP0.955NO
12 WP0.556NO
13 WP2.128
14 WP5.72
15 WP2.795NO
16 
Sum Ranges (2)
Cell Formulas
RangeFormula
G2:G16G2=IF(D2="","",SUM(SUMIFS(O2:O$100,L2:L$100,{"WP","BS"},AC2:AC$100,"<>NO"))-SUM(G3:G$100))
 
Upvote 0
I'm not quite sure how column H fits into it or the "T" in O1, but in any case I would be trying to avoid the volatile function OFFSET if possible.
Could we employ something like we did in another similar thread of yourd recently?

23 05 23.xlsm
DGHLOAC
1T
2RG6.32SP000000WP2.705
3 WP0.96NO
4 WP1.945NO
5 WP0.634NO
6 WP0.48NO
7 WP2.555
8 SP000001BS1.22NO
9 BS1.06
10 
11RG7.848SP000002WP0.955NO
12 WP0.556NO
13 WP2.128
14 WP5.72
15 WP2.795NO
16 
Sum Ranges (2)
Cell Formulas
RangeFormula
G2:G16G2=IF(D2="","",SUM(SUMIFS(O2:O$100,L2:L$100,{"WP","BS"},AC2:AC$100,"<>NO"))-SUM(G3:G$100))
Hi Peter,
I was using the offset function because when someone inserts rows into the spreadsheet it changes the "-SUM(G5:G$100)" function and no longer calculates correctly.
I think the volatile offset function will be okay to use as the workbook I'm creating is actually a weekly template and each sheet on it only gets used for the day.
It really works quite well for what I need it to do. I was hoping to just expand on the existing formula to include the part about not summing any values in column O that have the value No in column AC.
I have to be a bit careful with what information I share as some of it is sensitive but I have tried to pull together a test copy of the sheet so you can better see what I'm working with.

I have cleared out a lot of the column headers and only left the important ones but basically it's for organizing and tracking loads on trucks for a day.
Column AC is changed to no if a delivery is missed on a shipment. Each block of rows until a blank row represents an entire load.
The "from" column represents the location something is loaded from but the amount from the different location needs to still be included in the load (t) total.
I've added the table that the vlookup sources the rego, type and truck (t) from in its most basic form too underneath the main table.

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1
2
3Run #NameRegoTYPETruck (t)Plus/MinusLoad (t)ShipmentColumn1Column2Column3FROMColumn4Column5Tonnes (t)Column6Column7Column8Column9Column10Column11Column12Column13Column14Column15Column16Column17Column18Delv'd / RT'D
41TESTREG1RG12.00011.5591N/AN/AN/AWP2.705
5   N/AN/AN/AWP0.960
6   N/AN/AN/AWP1.945
7   N/AN/AN/AWP0.634
8   N/AN/AN/AWP0.480
9   N/AN/AN/AWP2.555
10   2N/AN/AN/ABS1.220
11   N/AN/AN/ABS1.060
12   
131TESTREG2RG12.50012.1543N/AN/AN/AWP0.955
14   N/AN/AN/AWP0.556
15   N/AN/AN/AWP2.128
16   N/AN/AN/AWP5.720
17   N/AN/AN/AWP2.795
18   
192TESTREG2RG12.50011.5704N/AN/AN/AWP11.570
20   
211TESTREG3RG16.00015.0005N/AN/AN/AWP15.000
22   
232TESTREG3RG16.00015.4506N/AN/AN/AWP6.782
24   N/AN/AN/AWP2.288
25   N/AN/AN/AWP6.380
26   
273TESTREG2RG12.50010.0007N/AN/AN/ABS10.000
28
29REGOTYPETruck (t)
30REG1RG12
31REG2RG12.5
32REG3RG16
Sheet1
Cell Formulas
RangeFormula
D4:D27D4=IFERROR(VLOOKUP(C4,Table1[#All],2,FALSE),"")
E4:E27E4=IFERROR(VLOOKUP(C4,Table1[#All],3,FALSE)+F4,"")
G4:G27G4=IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),SUM(O4:INDEX(O4:$O$100,MATCH(TRUE,($O4:O$100=""),0))),""),"")
Named Ranges
NameRefers ToCells
rego=Table1[REGO]D4:E27
type=Table1[TYPE]D4:E27
 
Upvote 0
I think the volatile offset function will be okay to use ..
I would still be looking for an alternative (& I'm almost certain there will be one) but to answeer your question, what about this?

Excel Formula:
=LET(r,MATCH(TRUE,($O4:O$101=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),SUMIF(AC4:INDEX(AC4:$AC$101,r),"<>NO",O4:INDEX(O4:$O$101,r)),""),""))

I note that this and your formula in post #4 now are taking no account of column L needing to be WP or BS. Has that requirement disappeared? Or going by your latest sample data, they are the only non-blank values in column L?

If you did want to investigate a non-volatile alternative, I would want to know (in words) just what this part of your formula is trying to do
IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),
In your sample data it seems that for every row that has a value in column D, the above conditions are met and for the only row where column H has a value and column D does not have a value the above conditions are not met.
Based on the given sample then, it would seem that we should only need to check if column D has a value to determine if a value is required in column G.
 
Upvote 1
Solution
I would still be looking for an alternative (& I'm almost certain there will be one) but to answeer your question, what about this?

Excel Formula:
=LET(r,MATCH(TRUE,($O4:O$101=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),SUMIF(AC4:INDEX(AC4:$AC$101,r),"<>NO",O4:INDEX(O4:$O$101,r)),""),""))

I note that this and your formula in post #4 now are taking no account of column L needing to be WP or BS. Has that requirement disappeared? Or going by your latest sample data, they are the only non-blank values in column L?

If you did want to investigate a non-volatile alternative, I would want to know (in words) just what this part of your formula is trying to do
IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),
In your sample data it seems that for every row that has a value in column D, the above conditions are met and for the only row where column H has a value and column D does not have a value the above conditions are not met.
Based on the given sample then, it would seem that we should only need to check if column D has a value to determine if a value is required in column G.
Hi Peter,
Yes, sorry! The requirement for only summing values that are "WP" and "BS" are still there for column L. I must have accidentally removed it in my attempt to make a testing sheet.

As for the logic behind needing the formula not to sum when H is blank, this is because until a shipment has a shipment number against it, the sum of the load is not finalized. Basically, nothing should sum unless a rego is assigned to the load (column d) or a shipment number is assigned to the load (column H).
Can both things be added back into your formula? Your new formula is great by the way. Way beyond me.

Book1.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1
2
3Run #NameRegoTYPETruck (t)Plus/MinusLoad (t)ShipmentColumn1Column2Column3FROMColumn4Column5Tonnes (t)Column6Column7Column8Column9Column10Column11Column12Column13Column14Column15Column16Column17Column18Delv'd / RT'D
41TESTREG1RG12.0009.0041N/AN/AN/AWP2.705
5   N/AN/AN/AWP0.960
6   N/AN/AN/AWP1.945
7   N/AN/AN/AWP0.634
8   N/AN/AN/AWP0.480
9   N/AN/AN/AWP2.555No
10   2N/AN/AN/ABS1.220
11   N/AN/AN/ABS1.060
12   
131TESTREG2RG12.50012.1543N/AN/AN/AWP0.955
14   N/AN/AN/AWP0.556
15   N/AN/AN/AWP2.128
16   N/AN/AN/AWP5.720
17   N/AN/AN/AWP2.795
18   
192TESTREG2RG12.50011.5704N/AN/AN/AWP11.570
20   
211TESTREG3RG16.00015.0005N/AN/AN/AWP15.000
22   
232TESTREG3RG16.00015.4506N/AN/AN/AWP6.782
24   N/AN/AN/AWP2.288
25   N/AN/AN/AWP6.380
26   
273TESTREG2RG12.50010.0007N/AN/AN/ABS10.000
Sheet1
Cell Formulas
RangeFormula
D4:D27D4=IFERROR(VLOOKUP(C4,Table1[#All],2,FALSE),"")
E4:E27E4=IFERROR(VLOOKUP(C4,Table1[#All],3,FALSE)+F4,"")
G4:G27G4=LET(r,MATCH(TRUE,($O4:O$96=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),SUMIF(AC4:INDEX(AC4:$AC$96,r),"<>NO",O4:INDEX(O4:$O$96,r)),""),""))
Named Ranges
NameRefers ToCells
rego=Table1[REGO]D4:E27
type=Table1[TYPE]D4:E27


The reason I have "IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)"))," in the formula because when new rows are inserted into the sheet, it was changing the "-SUM(G3:G$100))" in your original formula. The users of the sheet will frequently insert new rows to move/ split up shipments to assign them to different trucks etc. For example, if 5 rows are added below row 5 this makes the formula in G5 change from "-SUM(G6:G$100))" to be "-SUM(G11:G$100))". It will then revert back on row 6 to "-SUM(G7:G$100))" etc. See below. It could just be me being a noob.


Book1.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
3Run #NameRegoTYPETruck (t)Plus/MinusLoad (t)ShipmentColumn1Column2Column3FROMColumn4Column5Tonnes (t)Column6Column7Column8Column9Column10Column11Column12Column13Column14Column15Column16Column17Column18Delv'd / RT'D
41TESTREG1RG12.00011.5591N/AN/AN/AWP2.705
5   N/AN/AN/AWP0.960
6   
7   
8   
9   
10   
11   N/AN/AN/AWP1.945
12   N/AN/AN/AWP0.634
13   N/AN/AN/AWP0.480
14   N/AN/AN/AWP2.555
15   2N/AN/AN/ABS1.220
16   N/AN/AN/ABS1.060
17   
181TESTREG2RG12.50012.1543N/AN/AN/AWP0.955
19   N/AN/AN/AWP0.556
20   N/AN/AN/AWP2.128
21   N/AN/AN/AWP5.720
22   N/AN/AN/AWP2.795
23   
242TESTREG2RG12.50011.5704N/AN/AN/AWP11.570
25   
261TESTREG3RG16.00015.0005N/AN/AN/AWP15.000
27   
282TESTREG3RG16.00015.4506N/AN/AN/AWP6.782
29   N/AN/AN/AWP2.288
30   N/AN/AN/AWP6.380
31   
323TESTREG2RG12.50010.0007N/AN/AN/ABS10.000
Sheet1
Cell Formulas
RangeFormula
D4:D32D4=IFERROR(VLOOKUP(C4,Table1[#All],2,FALSE),"")
E4:E32E4=IFERROR(VLOOKUP(C4,Table1[#All],3,FALSE)+F4,"")
G4,G6:G32G4=IF(D4="","",SUM(SUMIFS(O4:O$105,L4:L$105,{"WP","BS"},AC4:AC$105,"<>NO"))-SUM(G5:G$105))
G5G5=IF(D5="","",SUM(SUMIFS(O5:O$105,L5:L$105,{"WP","BS"},AC5:AC$105,"<>NO"))-SUM(G11:G$105))
Named Ranges
NameRefers ToCells
rego=Table1[REGO]D4:E32
type=Table1[TYPE]D4:E32
 
Upvote 0
nothing should sum unless a rego is assigned to the load (column d) or a shipment number is assigned to the load (column H).
So why is there no value in cell G10 of post #4 since there is a shipment number in column H?
 
Upvote 0
So why is there no value in cell G10 of post #4 since there is a shipment number in column H?
Hi Peter,
There is no value in cell G10 due to the neither of the offset criteria being fulfilled. If row 9 cell O9 is not blank or equal to "Tonnes (t)" then the blank value is returned to G10.
In this formula however it does not account for the need to count only "WP" and "BS". It just sums everything until a blank cell is reached.
Your new formula is far better. Is there a way to amend it to include summing only for column O values where rows contain WP and BS as well as nothing summing unless a rego is assigned to the load (column d) or a shipment number is assigned to the load (column H)?

Excel Formula:
=LET(r,MATCH(TRUE,($O4:O$101=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),SUMIF(AC4:INDEX(AC4:$AC$101,r),"<>NO",O4:INDEX(O4:$O$101,r)),""),""))
 
Last edited by a moderator:
Upvote 0
Hi Peter,
There is no value in cell G10 due to the neither of the offset criteria being fulfilled. If row 9 cell O9 is not blank or equal to "Tonnes (t)" then the blank value is returned to G10.
In this formula however it does not account for the need to count only "WP" and "BS". It just sums everything until a blank cell is reached.
Your new formula is far better. Is there a way to amend it to include summing only for column O values where rows contain WP and BS as well as nothing summing unless a rego is assigned to the load (column d) or a shipment number is assigned to the load (column H)?
Excel Formula:
[CODE=xls]=LET(r,MATCH(TRUE,($O4:O$101=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),SUMIF(AC4:INDEX(AC4:$AC$101,r),"<>NO",O4:INDEX(O4:$O$101,r)),""),""))
[/CODE]
Hi Peter,

Would something like this work?

Excel Formula:
=LET(r,MATCH(TRUE,($O4:O$101=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),(SUMIF(AC4:INDEX(AC4:$AC$101,r),"<>NO",O4:INDEX(O4:$O$101,r))-SUMIF(L4:INDEX(L4:$L$101,r),"<>WP",O4:INDEX(O4:$O$101,r))-SUMIF(L4:INDEX(L4:$L$101,r),"<>BS",O4:INDEX(O4:$O$101,r))),""),""))
 
Upvote 0
Hi Peter,

Would something like this work?

Excel Formula:
=LET(r,MATCH(TRUE,($O4:O$101=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),(SUMIF(AC4:INDEX(AC4:$AC$101,r),"<>NO",O4:INDEX(O4:$O$101,r))-SUMIF(L4:INDEX(L4:$L$101,r),"<>WP",O4:INDEX(O4:$O$101,r))-SUMIF(L4:INDEX(L4:$L$101,r),"<>BS",O4:INDEX(O4:$O$101,r))),""),""))
Hi Peter,
It's long and complex and volitile but I think I worked it out.
The below will sum everything that is not NO in column AH along with everything that is from BS plus everything in column AH that is not NO along with everything that is from WP.
It's not affected by anyone inserting rows thanks to the offset and it wont sum anything at all if either the shipment or the type is blank.

Excel Formula:
=LET(r,MATCH(TRUE,($O4:O$101=""),0),IF(OR(H4<>"",D4<>""),IF(AND(O4<>"",OR(OFFSET(O4,-1,0)="",OFFSET(O4,-1,0)="Tonnes (t)")),SUMIFS(O4:INDEX(O4:$O$101,r),AC4:INDEX(AC4:$AC$101,r),"<>NO",L4:INDEX(L4:$L$101,r),"BS")+SUMIFS(O4:INDEX(O4:$O$101,r),AC4:INDEX(AC4:$AC$101,r),"<>NO",L4:INDEX(L4:$L$101,r),"WP"),""),""))
 
Upvote 0

Forum statistics

Threads
1,224,862
Messages
6,181,466
Members
453,045
Latest member
Abraxas_X

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