Description
Adds a constraint to the current problem. Equivalent to clicking Solver on the Tools menu and then clicking Add 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
SolverAdd(cellRef, relation, formulaText)
cellRef
Required. Reference to a cell or a range of cells that forms the left side of a constraint.
relation
Required. Specifies the arithmetic relationship between the left and right sides of the constraint. If 4 is chosen, cellRef must contain an integer, and formulaText should not be specified.
Relation
Arithmetic relationship
1
<=
2
=
3
>=
4
Cells referenced by cellRef must contain integers.
formulaText
Optional. The right side of the constraint.
Remarks
After constraints are added, you can manipulate them with the SolverChange and SolverDelete functions.
See Also
SolverChange Function, SolverDelete Function, SolverOk Function.
Example
This example uses the Solver functions to maximize gross profit in a business problem. The SolverAdd function is used to add three constraints to the current problem.
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")