Formula to stop calculations once result hits zero

TimLovell

New Member
Joined
May 8, 2024
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Good Morning,

Excel newbie here, trying to sort this out.

I have a series of calculations running on IF statements that I want to terminate once the result hits zero. Using previous calculations and a SEQUENCE command to lay out the dates for production, I am trying to list an estimated daily production amount over those days, but need the list to stop once it hits zero.

Current formulas:

In F22 = =IF(G21<F21,G21,F21)

In G22 = =G21-F22

I need them to only calculate into the range of dates that get listed with the SEQUENCE command under Production Estimate.

Thank you.
 

Attachments

  • Screenshot (1).png
    Screenshot (1).png
    36.3 KB · Views: 6

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.
Edit:
What is the formula for the SEQUENCE?
 
Upvote 0
I am using =WORKDAY.INTL(B5-1,SEQUENCE(B7),"0000011")

Where B5 is input manually as the production start date, and B7 is calculated with =SUM(INT((WEEKDAY(B5-{2,3,4,5,6})+B4-B5)/7)) where B4 is input manually as due date.
 
Upvote 0
One more question: What if the calculation doesn't hit 0 before the end of the sequence? Do you want to keep going or stop by the end of the sequence?
 
Upvote 0
One more question: What if the calculation doesn't hit 0 before the end of the sequence? Do you want to keep going or stop by the end of the sequence?
In that case I would want it to stop by the end of the sequence. Of course, if that happens I have made other critical errors in calculation that I would need to address.
 
Upvote 0
I couldn't think of a simple solution, so here's a recursive lambda.
In your name manager, add new name and call it "myLambdaFunction" and then insert this in the Refer to
Excel Formula:
=LAMBDA(start_value1, start_value2,
    LET(
        steps,
        IF(
            start_value1 <= start_value2,
            TEXT(start_value1, "0") & ", " & TEXT(start_value2, "0"),
            TEXT(start_value1, "0") & ", " & TEXT(start_value2, "0") & ", " & myLambdaFunction(start_value1 - start_value2, start_value2)
        ),
        IF(
            start_value1 <= start_value2,
            steps,
            steps & ", 0"
        )
    )
)
Test_Book3.xlsx
ABCDE
2
3
45/24/24
55/20/24
6
75
8
9
10
11
12
13
14
1510922658
165/20/242658
175/21/241092
185/22/241566
195/23/24474
205/24/240
Sheet2
Cell Formulas
RangeFormula
B7B7=SUM(INT((WEEKDAY(B5-{2,3,4,5,6})+B4-B5)/7))
B16:B20B16=WORKDAY.INTL(B5-1,SEQUENCE(B7),"0000011")
C16:C20C16=TAKE(UNIQUE(--TEXTSPLIT(myLambdaFunction(D15,C15),,", ")),B7)
Dynamic array formulas.
 
Upvote 1
Solution
I am getting a #SPILL error listed in that cell. I modified the locations to match the ones on my sheet (In this case, D15 and C15 were replaced with G21 and F21).

I've never used the Name Manager before, but I followed the directions on naming and cut and paste the formula into the "Refers to" field.
 
Upvote 0
I am getting a #SPILL error listed in that cell
Do you understand how Spill functions work?
You just place the formula in one single cell, and the answer will "spill" into the other cells (usually rows below but also can be columns to the right).
So the cells that it is trying to spill over into must be empty.
If you are getting a #SPILL error, it means that you already have something in one of the cells it is trying to spill over into.
 
Upvote 0
Got it - thank you. As mentioned - Excel newbie here - did not know what SPILL was until you just explained it. Appreciate the help.
 
Upvote 0
You are welcome.

So, did Cubist's solution solve your problem?
If so, you can mark his post as the solution.
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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