SolverOk Function

Description

Defines a basic Solver model. Equivalent to clicking Solver on the Tools menu 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. With a Visual Basic module active, click References on the Tools menu, and then select the Solver.xla check box in the Available References box. If Solver.xla doesn't appear in the Available References box, click Browse, click Solver in the \Excel\Library\Solver folder, and then click OK.

Syntax

SolverOk(setCell, maxMinVal, valueOf, byChange)

setCell

Optional. Refers to a single cell on the active worksheet. Corresponds to the Set Target Cell box in the Solver Parameters dialog box.

maxMinVal

Optional. Corresponds to the Max, Min, and Value Of options in the Solver Parameters dialog box.

maxMinVal

Specifies

1

Maximize

2

Minimize

3

Match specific value


valueOf

Optional. If MaxMinVal is 3, you must specify the value to which the target cell is matched.

byChange

Required. The cell or range of cells that will be changed in order to obtain the desired result in the target cell. Corresponds to the By Changing Cells box in the Solver Parameters dialog box.

See Also

SolverOkDialog Function.

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")