This documentation is archived and is not being maintained.

SolverOk Function

Office 2007

Defines a basic Solver model. Equivalent to clicking Solver in the Data | Analysis group and then specifying options in the Solver Parameters dialog box.

Before you use this function, you must establish a reference to the Solver add-in. In the Visual Basic Editor, with a module active, click References on the Tools menu, and then select the Solver.xlam check box under Available References. If Solver.xlam does not appear under Available References, click Browse and open Solver.xlam in the \office12\library\Solver subfolder.


SolverOk(SetCell, MaxMinVal, ValueOf, ByChange)


MaxMinVal Specifies
1Maximize
2Minimize
3Match a specific value

Example

This example uses the Solver functions to maximize gross profit in a business problem. The SolverOK function defines a problem by specifying the SetCell, MaxMinVal, and ByChange arguments.

Worksheets("Sheet1").Activate
SolverReset
SolverOptions precision:=0.001
SolverOK SetCell:=Range("TotalProfit"), _
    MaxMinVal:=1, _
    ByChange:=Range("C4:E6")
SolverAdd CellRef:=Range("F4:F6"), _
    Relation:=1, _
    FormulaText:=100
SolverAdd CellRef:=Range("C4:E6"), _
    Relation:=3, _
    FormulaText:=0
SolverAdd CellRef:=Range("C4:E6"), _
    Relation:=4
SolverSolve UserFinish:=False
SolverSave SaveArea:=Range("A33")


Show: