+ Reply to Thread
Results 1 to 2 of 2

Run Solver Multiple Times (while changing constraints and goal for each iteration)

  1. #1
    Registered User
    Join Date
    02-03-2013
    Location
    Dallas,TX
    MS-Off Ver
    Excel 2010
    Posts
    1

    Question Run Solver Multiple Times (while changing constraints and goal for each iteration)

    Hi All,
    First of all, I am new to the Excel Forum, and have a problem to start out with.

    I am having some trouble with getting VBA to run the solver. I have already gone through adding the solver add-in as well as checking solver in VBA References.

    I would like solver to run multiple times, while after each time solver runs, I want to increase the row count for all goals and constraints.

    I am encountering an error message: "Run-time error '438': Object doesn't support this property or method" on my SolverOK line.

    Any suggestions?
    Thanks!

    Sub solveAll()
    '
    ' Macro2 Macro
    '

    '
    Dim cellChange As Range
    Dim cellGoal As Range
    Dim cellConstraint As Range
    Dim cellConstraintTotalPayed1 As Range
    Dim cellConstraintTotalPayed2 As Range
    Dim cellConstraintTotalPayed3 As Range
    Dim cellConstraintIntCharged1 As Range
    Dim cellConstraintIntCharged2 As Range
    Dim cellConstraintIntCharged3 As Range

    Set cellChange = ActiveSheet.Range("S17:U17")
    Set cellGoal = ActiveSheet.Range("V18")
    Set cellConstraintTotalPayed1 = ActiveSheet.Range("S17")
    Set cellConstraintTotalPayed2 = ActiveSheet.Range("T17")
    Set cellConstraintTotalPayed3 = ActiveSheet.Range("U17")
    Set cellConstraintIntCharged1 = ActiveSheet.Range("P17")
    Set cellConstraintIntCharged2 = ActiveSheet.Range("Q17")
    Set cellConstraintIntCharged3 = ActiveSheet.Range("R17")
    Set cellConstraintMonthlyMax = ActiveSheet.Range("W17")

    Do
    SolverReset
    SolverOK SetCell:=cellGoal.Address(True, True), MaxMinVal:=2, ByChange:=cellChange.Adress(True, True)
    SolverAdd CellRef:=cellConstraintMonthlyMax.Adress(True, True), Relation:=1, FormulaText:="$N$5"
    SolverAdd CellRef:=cellConstraintTotalPayed1.Adress(True, True), Relation:=3, FormulaText:=cellConstraintIntCharged1.Adress(True, True)
    SolverAdd CellRef:=cellConstraintTotalPayed2.Adress(True, True), Relation:=3, FormulaText:=cellConstraintIntCharged2.Adress(True, True)
    SolverAdd CellRef:=cellConstraintTotalPayed3.Adress(True, True), Relation:=3, FormulaText:=cellConstraintIntCharged3.Adress(True, True)
    Solver.SolverSolve UserFinish:=True

    Set cellChange = cellChange.Offset(0, 1)
    Set cellGoal = cellGoal.Offset(0, 1)
    Set cellConstraintTotalPayed1 = cellConstraintTotalPayed1.Offset(0, 1)
    Set cellConstraintTotalPayed2 = cellConstraintTotalPayed2.Offset(0, 1)
    Set cellConstraintTotalPayed3 = cellConstraintTotalPayed3.Offset(0, 1)
    Set cellConstraintIntCharged1 = cellConstraintIntCharged1.Offset(0, 1)
    Set cellConstraintIntCharged2 = cellConstraintIntCharged2.Offset(0, 1)
    Set cellConstraintIntCharged3 = cellConstraintIntCharged3.Offset(0, 1)
    Set cellConstraintMonthlyMax = cellConstraintMonthlyMax.Offset(0, 1)

    Loop While Trim(cellGoal.Text) > "9"

    End Sub

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Run Solver Multiple Times (while changing constraints and goal for each iteration)

    You have Address misspelled as Adress many times, including that line.

    Also, cellConstraintMonthlyMax is not declared.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1