Macro or VB to Subtract from a cell until criterias are met.

Arle8907

New Member
Joined
Apr 16, 2024
Messages
3
Platform
  1. Windows
Hello, I have a sheet that calculates the maximum load a beam can hold for a given span, and I am working on populating a table with the values. The cells i can change are the beam size, span, and max load. Based on those inputs the sheet calculates four different failure modes, and displays a pass/fail output for each. What i am hoping to do is manually input the beam size and span, then have excel start at some large number and subtract 0.1 from the number until all four of the pass/fail outputs show pass.

Thank you for your time.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Why not use the GoalSeek feature?
I tried that but i think since my criteria aren't formulas it can't find the slope of the equation to determine the answer. It looks like it bounces around randomly until it eventually hits the iteration limit.
 
Upvote 0
since my criteria aren't formulas

There must be formulas somewhere otherwise your plan to subtract 0.1 until you get a good result (which is iteration) is not going to work either.
 
Upvote 0
There must be formulas somewhere otherwise your plan to subtract 0.1 until you get a good result (which is iteration) is not going to work either.
With the way this spreadsheet is set up unfortunately there is not without significant rework of the spreadsheet. With the work around i have right now it would take me longer to rework/develop a new sheet than it would to guess and check each value manually.

If cells A1, A2, A3, & A4 contain the true/false statements
cell A5=A1+A2+A3+A4 then since True=1 and false=0 if A5=4 all the conditions are true.
There is no way for excel to say If A5<>4 then *Max Load*-0.1 and check again?

Thank you for the help
 
Upvote 0
With the way this spreadsheet is set up unfortunately there is not without significant rework of the spreadsheet. With the work around i have right now it would take me longer to rework/develop a new sheet than it would to guess and check each value manually.

I'm not sure that is true. It is possible to goal seek a True/False output as long as you understand the formula that produced the True/False. One simple example
Book1
ABCDEFGH
1InputFail ModeMode StatusFail CalcSumCombined Pass/Fail
2Beam Size101Pass1040Pass
3Span442Pass10
4Max Load779.23Pass10
54Pass10
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=IF(F2=10,"Pass","Fail")
F2F2=IF($B$2+$B$3*$B$4>30000,10,0)
G2G2=SUM(F2:F5)
H2H2=IF(G2=40,"Pass","Fail")
F3F3=IF($B$2*$B$3*$B$4>15000,10,0)
F4F4=IF($B$2+$B$3*$B$4*2<1500000,10,0)
F5F5=IF($B$2*$B$3*$B$4*3>110000,10,0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H2,E2:E5Cell Value="Fail"textNO
H2,E2:E5Cell Value="Pass"textNO

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'
    Range("G2").GoalSeek Goal:=40, ChangingCell:=Range("B4")
End Sub
 
Upvote 0
If cells A1, A2, A3, & A4 contain the true/false statements
cell A5=A1+A2+A3+A4 then since True=1 and false=0 if A5=4 all the conditions are true.
There is no way for excel to say If A5<>4 then *Max Load*-0.1 and check again?

One way.
VBA Code:
Sub TestAndCheck()
    Dim MaxLoad As Double
    Dim FoundResult As Boolean

    With ActiveSheet
        MaxLoad = .Range("E2").Value
        Do While MaxLoad > 0
            FoundResult = .Range("A5").Value
            If FoundResult Then
                Exit Do
            End If
            MaxLoad = Round(MaxLoad - 0.1, 1)
            .Range("E2").Value = MaxLoad
        Loop
    End With
    If Not FoundResult Then
        MsgBox "No Convergence", vbOKOnly Or vbCritical, "Failure to Converge"
    End If
End Sub

Book1
ABCDE
1FALSEBeam SizeSpanMax Load
2FALSE1044800
3TRUE
4FALSE
5FALSE
Sheet2
Cell Formulas
RangeFormula
A1A1=$E$2<= 500
A2A2=$E$2<= 700
A3A3=$E$2<= 900
A4A4=$E$2<= 399
A5A5=AND(A1:A4)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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