Solver VBA question - automation

pdhil87

New Member
Joined
Aug 27, 2018
Messages
8
Hi

I am trying to automate a solver procedure and have the following code:
The iteration procedure is working - moving the constraint from R15 to 16....etc as planned
However the procedure seems to be loosing the second constraint of Cell K27 =1
Any advice appreciated!

Thanks

Sub RunSolver()
'
Dim i As Integer


For i = 0 To 33




' RunSolver Macro
SolverReset

'
SolverOk SetCell:="$B$32", MaxMinVal:=2, ValueOf:=0, ByChange:="$K$20:$K$25", _
Engine:=1, EngineDesc:="GRG Nonlinear"

SolverOk SetCell:="$B$32", MaxMinVal:=2, ValueOf:=0, ByChange:="$K$20:$K$25", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$B$29", Relation:=2, FormulaText:=Sheets("Sheet2").Range("$R$15").Offset(i, 0).Address
SolverOk SetCell:="$B$32", MaxMinVal:=2, ValueOf:=0, ByChange:="$K$20:$K$25", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$K$27", Relation:=2, FormulaText:="1"
SolverOk SetCell:="$B$32", MaxMinVal:=2, ValueOf:=0, ByChange:="$K$20:$K$25", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:="$B$32", MaxMinVal:=2, ValueOf:=0, ByChange:="$K$20:$K$25", _
Engine:=1, EngineDesc:="GRG Nonlinear"

SolverSolve UserFinish:=True
SolverFinish KeepFinal:=1
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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