Results 1 to 3 of 3

Thread: Running Solver with VBA

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2001
    Location
    Montreal, Quebec
    Posts
    400

    Running Solver with VBA

    I'm using this code to run Solver with VBA. When I run it, there is no solution (or Solver Results dialog box). When I check the Solver Parameters under "Tools" ,I see that the constraints and MaxMinVal are entered correctly. But there are no entries for "Set Target Cell or "By Changing Cells". What have I done wrong?
    VB Code:
    1. Sub RunSolver()
    2.  
    3. 'Prompt for month number
    4. currMonth = Application.InputBox(Prompt:="Enter month number:", Type:=2)
    5.  
    6. 'Clear previous Solver settings
    7. SolverReset
    8.          
    9.     ' Solver Options...
    10.     Call SolverOptions(MaxTime:=100, Iterations:=200, Precision:=0.0001, AssumeLinear _
    11.         :=True, StepThru:=False, Estimates:=1, Derivatives:=1, SearchOption:=1, _
    12.         IntTolerance:=5, Scaling:=False, Convergence:=0.0001, AssumeNonNeg:=True)
    13.  
    14.  
    15. ' The Solver will run one month at a time. Using the first month as
    16. ' the starting point, use intOffset to determine which month (column)
    17. ' to solve for
    18.  
    19.     intOffset = currMonth - 1
    20.  
    21.     ' Set the target cell to a minimum value by changing cells C11:C22 or
    22.     ' an offset of this range
    23.     SolverOk SetCell:=Range("Total_Cost"), MaxMinVal:=2, _
    24.         ByChange:=Range("Ship").Offset(0, intOffset)
    25.    
    26.     ' Add the constraint that Final Inventory <= Capacity
    27.     SolverAdd CellRef:=Range("Final_Inventory").Offset(0, intOffset), Relation:=1, _
    28.         FormulaText:=Range("Capacity").Offset(0, intOffset)
    29.    
    30.     ' Add the constraint that Final Inventory >= Safety Stock
    31.     SolverAdd CellRef:=Range("Final_Inventory").Offset(0, intOffset), Relation:=3, _
    32.         FormulaText:=Range("Safety_Stock").Offset(0, intOffset)
    33.  
    34.     ' Add the constraint that shipments to customer = customer demand.
    35.     SolverAdd CellRef:=Range("Net_Flow_Cust").Offset(0, intOffset), Relation:=2, _
    36.         FormulaText:=Range("Demand_Cust").Offset(0, intOffset)
    37.    
    38.     ' Add the constraint that shipments from PM = PM Production.
    39.     SolverAdd CellRef:=Range("Net_Flow_PM").Offset(0, intOffset), Relation:=2, _
    40.         FormulaText:=Range("Supply_PM").Offset(0, intOffset)
    41.  
    42.     ' Add the constraint that shipments from WHSE >= WHSE Demand.
    43.     SolverAdd CellRef:=Range("Net_Flow_WHSE").Offset(0, intOffset), Relation:=3, _
    44.         FormulaText:=Range("Demand_WHSE").Offset(0, intOffset)
    45.    
    46.     ' Solve the model and keep the final results.
    47.     SolverSolve UserFinish:=False
    48.     'SolverFinish KeepFinal:=1
    49.  
    50. End Sub
    Last edited by Stan; Aug 19th, 2005 at 04:03 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width