SolverAdd Function

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.

Note Note

The Solver add-in is not enabled by default. Before you can use this function, the Solver add-in must be enabled and installed. For information about how to do that, see Using the Solver VBA Functions. After the Solver add-in is installed, 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 Solver under Available References. If Solver does not appear under Available References, click Browse, and then open Solver.xlam in the \Program Files\Microsoft Office\Office14\Library\SOLVER subfolder.

SolverAdd(CellRef, Relation, FormulaText)

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.


Arithmetic relationship








Cells referenced by CellRef must have final values that are integers.


Cells referenced by CellRef must have final values of either 0 (zero) or 1.


Cells referenced by CellRef must have final values that are all different and integers.

FormulaText Optional Variant. The right side of the constraint.

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

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.

SolverOptions precision:=0.001 
SolverOK setCell:=Range("TotalProfit"), _ 
 maxMinVal:=1, _ 
SolverAdd cellRef:=Range("F4:F6"), _ 
 relation:=1, _ 
SolverAdd cellRef:=Range("C4:E6"), _ 
 relation:=3, _ 
SolverAdd cellRef:=Range("C4:E6"), _ 
SolverSolve userFinish:=False 
SolverSave saveArea:=Range("A33")