I'm using this code to run Solver with VBA. When I run it, there is no solution (or Solver Results dialog box). I check the Solver under "Tools" and see that the constraints and MaxMinVal are set OK. But there are no entries for SetCell or ByChange. What have I done wrong?
Code
Sub RunSolver()
'Prompt for month number
currMonth = Application.InputBox(Prompt:="Enter month number:", Type:=2)
'Clear previous Solver settings
SolverReset
' The Solver will run one month at a time. Using the first month as
' the starting point, use intOffset to determine which month (column)
' to solve for
intOffset = currMonth - 1
' Set the target cell to a minimum value by changing cells C11:C22 or
' an offset of this range
SolverOk SetCell:=Range("R23"), MaxMinVal:=2, _
ByChange:=Range("C11:C22").Offset(0, intOffset)
' Add the constraint that Final Inventory <= Capacity
SolverAdd CellRef:=Range("C25:C28").Offset(0, intOffset), Relation:=1, _
FormulaText:=Range("C59:C62").Offset(0, intOffset)
' Add the constraint that Final Inventory >= Safety Stock
SolverAdd CellRef:=Range("C25:C28").Offset(0, intOffset), Relation:=3, _
FormulaText:=Range("C53:C56").Offset(0, intOffset)
' Add the constraint that shipments to customer = customer demand.
SolverAdd CellRef:=Range("C42").Offset(0, intOffset), Relation:=2, _
FormulaText:=Range("C8").Offset(0, intOffset)
' Add the constraint that shipments from PM = PM Production.
SolverAdd CellRef:=Range("C37").Offset(0, intOffset), Relation:=2, _
FormulaText:=Range("C5").Offset(0, intOffset)
' Add the constraint that shipments from WHSE >= WHSE Demand.
SolverAdd CellRef:=Range("C38:C41").Offset(0, intOffset), Relation:=3, _
FormulaText:=Range("C46:C49").Offset(0, intOffset)
' Solve the model
SolverSolve UserFinish:=False
'SolverFinish KeepFinal:=1
End Sub
Display More