Hi,
First of all, I'd like to say thanks to everyone here; I've picked up more on this forum than from any book...
I have constructed a macro that calls solver, enters constraints and solves the optimization problem. However, for some constraints there will be no solutions. Unfortunately, solver will give me the nearest value instead of stating N/A (which I would prefer). Is there a code to resolve this? Thanks in advance! (Below is my code, which I know is inefficient, but don't mind that, I'll work on that later).
Sub SOLVER()
'
' Solver Macro
' Macro recorded 30-5-2007 by
'
Application.ScreenUpdating = False
SolverReset
SolverOk SetCell:="$M$7", MaxMinVal:=2, ValueOf:="0", ByChange:="$B$4:$H$4"
SolverAdd CellRef:="$B$4", Relation:=3, FormulaText:="$N$30"
SolverAdd CellRef:="$B$4", Relation:=1, FormulaText:="$O$30"
SolverAdd CellRef:="$C$4", Relation:=3, FormulaText:="$N$31"
SolverAdd CellRef:="$C$4", Relation:=1, FormulaText:="$O$31"
SolverAdd CellRef:="$D$4", Relation:=3, FormulaText:="$N$32"
SolverAdd CellRef:="$D$4", Relation:=1, FormulaText:="$O$32"
SolverAdd CellRef:="$E$4", Relation:=3, FormulaText:="$N$34"
SolverAdd CellRef:="$E$4", Relation:=1, FormulaText:="$O$34"
SolverAdd CellRef:="$F$4", Relation:=1, FormulaText:="$O$33"
SolverAdd CellRef:="$F$4", Relation:=3, FormulaText:="$N$33"
SolverAdd CellRef:="$G$4", Relation:=1, FormulaText:="$O$33"
SolverAdd CellRef:="$G$4", Relation:=3, FormulaText:="$N$33"
SolverAdd CellRef:="$H$4", Relation:=1, FormulaText:="$O$34"
SolverAdd CellRef:="$H$4", Relation:=3, FormulaText:="$N$34"
SolverAdd CellRef:="$K$2", Relation:=2, FormulaText:="$J$4"
SolverAdd CellRef:="$M$6", Relation:=2, FormulaText:="$M$9"
SolverOk SetCell:="$M$7", MaxMinVal:=2, ValueOf:="0", ByChange:="$B$4:$H$4"
SolverSolve userFinish:=True
Thanks again, kind regards,
Peter1999
Bookmarks