Adds a constraint to the current problem. Equivalent to clicking Solver in the Data | Analysis group 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. 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 \office14\library\Solver subfolder.

CellRef   Required Variant. A reference to a cell or a range of cells that forms the left side of a constraint.
Relation   Required Integer. The arithmetic relationship between the left and right sides of the constraint. If you choose 4, 5 or 6, CellRef must refer to decision variable cells, and FormulaText should not be specified.

 Relation Arithmetic relationship 1 <= 2 = 3 >= 4 Cells referenced by CellRef must have final values that are integers. 5 Cells referenced by CellRef must have final values of either 0 (zero) or 1. 6 Cells referenced by CellRef must have final values that are all different and integers.

FormulaText   Optional Variant. The right side of the constraint.

Remarks

After constraints are added, you can manipulate them with the SolverChange and SolverDelete functions.

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"). ActivateSolverResetSolverOptions precision:=0.001SolverOK setCell:=Range ("TotalProfit"), _    maxMinVal:=1, _    byChange:=Range ("C4:E6")SolverAdd cellRef:=Range ("F4:F6"), _    relation:=1, _    formulaText:=100SolverAdd cellRef:=Range ("C4:E6"), _    relation:=3, _    formulaText:=0SolverAdd cellRef:=Range ("C4:E6"), _    relation:=4SolverSolve userFinish:=FalseSolverSave saveArea:=Range ("A33")