PDA

View Full Version : SolverAdd ignores certain constraints



midknight
02-03-2013, 05:23 AM
I have been banging my head against the wall trying to sort this out. I'm trying to set up a macro to run solver for a reoccurring engineering problem I am working on. However, SolverAdd refuses to recognize "6", "7", "8", and "9" as constraints. It will recognize the constraints if I use 6.0000001 instead of 6. Any ideas?
The following is the stripped down code:
Sub Solver_HW()
'
' Solver_HW Macro
' Solve K20 for a given component across HW
'
SolverReset
SolverOk SetCell:="$Q$1", MaxMinVal:=2, ValueOf:=0, ByChange:= _
"$Q$2:$Q$3,$N$5,$P$5", Engine:=1, EngineDesc:="GRG Nonlinear"

SolverAdd CellRef:="$Q$2", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$Q$2", Relation:=1, FormulaText:="6.0001"
SolverAdd CellRef:="$Q$3", Relation:=1, FormulaText:="1.2"
SolverAdd CellRef:="$Q$3", Relation:=3, FormulaText:="0.88"
SolverAdd CellRef:="$N$5", Relation:=3, FormulaText:="1"
SolverAdd CellRef:="$N$5", Relation:=1, FormulaText:="6"


SolverAdd CellRef:="$P$5", Relation:=2, FormulaText:="2"
SolverAdd CellRef:="$P$5", Relation:=3, FormulaText:="0.01"
SolverAdd CellRef:="$N$5", Relation:=4, FormulaText:="integer"


SolverSolve
End Sub

midknight
02-03-2013, 09:46 PM
For any who have the same issue, I found a solution:
When writing a number as a constraint, write "=#"
i.e.
SolverAdd CellRef:="$N$5", Relation:=1, Formulatext:="=6"

Thanks to falcad at "Windows Secrets Lounge" for posting this tip back in 2008.