MrShorty, there is no square term so it is not a quadratic equation.
The only way that I know to solve row 2 is to copy the formula from row 3. Doing that, does change all the w and WL values. I think that is the right way to go though.
Dim glb_origCalculationMode As Integer
Sub Main()
Dim c As Range, r&
SpeedOn
On Error GoTo EndSub
For Each c In Range("A2", Range("A2").End(xlDown))
r = c.Row
mSolver Cells(r, "P").Address, Cells(r, "L").Address, Cells(r, "K").Address
Next c
EndSub:
SpeedOff
End Sub
Sub SpeedOn(Optional StatusBarMsg As String = "Running macro...")
glb_origCalculationMode = Application.Calculation
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
.Cursor = xlWait
.StatusBar = StatusBarMsg
.EnableCancelKey = xlErrorHandler
End With
End Sub
Sub SpeedOff()
With Application
.Calculation = glb_origCalculationMode
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.CalculateBeforeSave = True
.Cursor = xlDefault
.StatusBar = False
.EnableCancelKey = xlInterrupt
End With
End Sub
'https://msdn.microsoft.com/en-us/library/office/ff838657.aspx
'Tools > References > Solver 'Must enable Solver add-in first, then add reference.
Sub mSolver(sSetCell$, sByChange$, sFormulaText$)
SolverReset
SolverOk SetCell:=sSetCell, MaxMinVal:=1, ValueOf:=0, ByChange:=sByChange, Engine:=1 _
, EngineDesc:="GRG Nonlinear"
'Relation=2=equals
SolverAdd CellRef:=sSetCell, Relation:=2, FormulaText:=sFormulaText
' Do not display the Solver Results dialog box?
SolverSolve UserFinish:=True 'True=do not show, False=do show.
End Sub
Bookmarks