Solver VBA doesn't apply all constraints

Copper Contributor

I have the following VBA code:

 

SolverReset
SolverOk SetCell:="$C$27", MaxMinVal:=1, ValueOf:=0, ByChange:="$C$22:$C$24", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$C$24", Relation:=1, FormulaText:="($C$22+$C$23)*2"
SolverAdd CellRef:="$C$30", Relation:=1, FormulaText:="3"
SolverAdd CellRef:="$C$30", Relation:=3, FormulaText:="1"
SolverAdd CellRef:="$C$22", Relation:=1, FormulaText:="12"
SolverAdd CellRef:="$C$23", Relation:=1, FormulaText:="3"
SolverAdd CellRef:="$C$24", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$C$22", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$C$23", Relation:=4, FormulaText:="integer"
SolverAdd CellRef:="$C$24", Relation:=4, FormulaText:="integer"
SolverOk SetCell:="$C$27", MaxMinVal:=1, ValueOf:=0, ByChange:="$C$22:$C$24", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve userFinish:=True

 

when I run it the solver doesn't apply the constraint C30 >= 1, and when I open up the solver dialog to see the constraints used it is missing from the solver.

If the constraint is then added in the dialog it does get solved properly.

2 Replies

@JoelF514 I'm having a similar issue.  Were you able to find a resolution?

@TSDutton   Similar how?  That's rhetorical.  The point is:  describe __your__ problem.

 

And I suspect that you really don't care if @JoelF514  per se found a solution.  Instead, you would like someone -- anyone -- to solve __your__ problem.

 

When you describe your problem, don't make the mistake that @JoelF514  did.  Be sure to provide sufficient information that allows us to reproduce your problem.  (FYI, I could not duplicate the problem with the limited informtion that @JoelF514   provided.)  Usually, that means all formulas in any cell that the objective cell depends on, directly or indirectly.

 

The best and perhaps simplest way to do that is by attaching an example Excel file (redacted) that demonstrates your problem.

 

Finally, be sure to let us know what version of Excel you are using, and on what platform (PC or Mac).  And if you are using Office 365, my understanding is:  it is useful to know the "channel" and the build version.