Consulting

Results 1 to 2 of 2

Thread: SolverAdd ignores certain constraints

  1. #1

    Post SolverAdd ignores certain constraints

    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

  2. #2
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •