Excel Solver: Add Decision Variables and Set Constraints

How-to basics · Updated November 18, 2026

Yes. To add variables in Excel Solver, put each decision variable in a worksheet cell and include those cells in the Solver Parameters dialog’s By Changing Variable Cells box. If you add another variable later, expand that cell range and update any objective or constraint formulas that need to use it.

What “adding variables” means in Solver

Solver does not have a separate “Add Variable” button. Instead, it changes the values in worksheet cells to find a solution. Those cells are called changing variable cells or decision-variable cells. For example, a production model might use one cell for the number of chairs to make and another for the number of desks.

The cells need to contain numeric starting values, such as 0. They should not contain formulas: Solver adjusts their values. Other cells calculate the result of those choices. One formula cell might calculate total profit, while additional formula cells calculate how much labor or material the plan uses. Solver then changes the decision cells while respecting the limits you specify.

That distinction is useful when you are troubleshooting. The variable cells are the choices Solver may change; the objective cell measures what you want to optimize; and the constraints describe what the choices are allowed to be.

Prepare the worksheet before opening Solver

Arrange the decision cells together when practical. A single continuous range, such as B2:D2, is easier to recognize and maintain than scattered cells. Put clear labels beside the cells so you can tell which variable each one represents. Give the objective and constraint calculations their own cells, with labels that explain what each result means.

  • Enter a starting value in every decision-variable cell. Zero is often a reasonable starting point, though some nonlinear models may need a more useful initial estimate.
  • Build a formula for the quantity to maximize or minimize, such as profit, cost, distance, or time.
  • Calculate each limited resource or requirement in a worksheet cell so you can compare it with its permitted limit.
  • Check that the formulas refer to the intended variable cells before asking Solver to run.

If Solver is not on the Data tab in Excel for Microsoft 365 on Windows, enable the add-in through File > Options > Add-ins. At the bottom, choose Excel Add-ins in the Manage box, click Go, select Solver Add-in, and click OK. Solver is a desktop add-in; Excel for the web does not provide the same Solver add-in workflow, so open the workbook in the desktop app to use it. In Excel for Mac, enable it from Tools > Excel Add-ins, select Solver, and then look for Solver on the Data tab.

How to add or expand variables in Solver

  1. On the worksheet, create a numeric cell for each choice Solver should control. If the model already has two variable cells and you need a third, add a new cell and label it clearly.
  2. Choose Data > Solver to open Solver Parameters.
  3. Set the objective by selecting the cell containing the result you want to optimize. Choose Max, Min, or Value Of, depending on the goal.
  4. Click the By Changing Variable Cells box, then select the complete range of decision cells on the worksheet. You can also enter a reference such as $B$2:$D$2.
  5. If you are editing an existing model, replace or extend the old range so it includes the new variable. Check that it does not accidentally include a label, a formula cell, or an unrelated input.
  6. Click Add in the Subject to the Constraints area to enter limits, then choose a solving method and click Solve.

Adding the new cell to the changing range is only part of the update. The objective formula and any relevant resource formulas must also include the new decision. Otherwise, Solver may change the cell without that choice affecting the result. For example, if a new product has a profit contribution, include its quantity in the profit calculation; if it uses a limited material, include that use in the material calculation.

Worked example: two products and two limits

Suppose a small workshop makes products A and B. Let B2 hold the quantity of A and C2 the quantity of B. Each A earns $30 and each B earns $50. The workshop has 100 units of one resource and 90 units of another. Each A uses 2 units of the first resource and 3 of the second; each B uses 4 of the first and 2 of the second.

With product quantities in B2 and C2, and the profit result in D2, enter this objective formula in D2:

=30*B2+50*C2

With B2 and C2 holding the product quantities and the first resource total in D4, enter this formula in D4:

=2*B2+4*C2

With the same quantities and the second resource total in D5, enter this formula in D5:

=3*B2+2*C2

In Solver, set the objective to D2 and choose Max. Set the changing variable cells to B2:C2. Add constraints D4 <= 100 and D5 <= 90, and require B2 and C2 to be nonnegative. If the products must be made in whole units, also add integer constraints for those variable cells. Choose Simplex LP because the objective and resource calculations are linear.

One optimal solution is B2 = 20 and C2 = 15. It earns 30 × 20 + 50 × 15 = $1,350. The first resource use is 2 × 20 + 4 × 15 = 100, and the second is 3 × 20 + 2 × 15 = 90, so both limits are met exactly. This example also shows why a variable must be included in the objective and in any resource calculations it affects.

Set limits and variable types

Use Solver constraints to express the rules the answer must follow. Click Add in the constraint area, select a cell reference, choose a relationship such as <=, =, or >=, and enter a number or another cell reference. A constraint can limit a calculated total, require a variable to stay below a capacity, or enforce a particular type of value.

  • Nonnegative values: Use the Make Unconstrained Variables Non-Negative option, or add explicit lower-bound constraints where appropriate.
  • Whole numbers: Choose int for variables that cannot be fractional, such as people, machines, or units sold.
  • Yes-or-no choices: Choose bin for binary variables restricted to 0 or 1. These can represent decisions such as whether to open a location.
  • Bounds: Add lower or upper limits when the worksheet rules require them, such as a minimum production quantity or a maximum available capacity.

Do not add an integer or binary restriction just because a variable is called a decision variable. A continuous quantity, such as a blend proportion, may legitimately be fractional. Extra restrictions can make a model harder to solve or change its correct answer, so use the type that matches the real problem.

Choose the right Solver method

The solving method should match the mathematics in the worksheet, not just the topic of the problem. For a model with linear objective and constraint formulas, choose Simplex LP. A formula is linear when each variable appears to the first power and is not multiplied by another variable. The production example above is linear.

Choose GRG Nonlinear for smooth nonlinear formulas, such as a model involving a variable raised to a power or a smooth nonlinear relationship. Choose Evolutionary for models with discontinuities or relationships that are not smooth, where the other methods may not be suitable. Solver results from nonlinear or evolutionary models can depend on starting values and may require careful review. A method cannot make an incorrectly built model correct: verify the formulas, constraints, and units first.

Common problems when adding variables

  • The new variable is ignored. Check that its cell is included in By Changing Variable Cells. Then confirm that the objective and applicable constraint formulas also refer to it.
  • Solver reports no feasible solution. Review the limits for contradictions, such as a minimum quantity that exceeds a maximum, or resource requirements that cannot all be met. Temporarily inspect the worksheet calculations using sensible sample values.
  • The answer contains fractions. If the real decision requires whole units, add an integer constraint. Without it, Solver is allowed to return fractional values.
  • The result looks unreasonable. Check whether the objective is set to Max or Min as intended, whether the correct objective cell is selected, and whether all relevant limits are present. Also check that units are consistent—for example, hours should not be compared with minutes without conversion.
  • Solver cannot find a solution quickly. Reduce unnecessary variables and constraints, use the method suited to the formulas, and avoid adding cells that do not represent genuine choices. Standard Solver has a limit of 200 changing variable cells, so a model with more variables may need redesign or another optimization tool.

After Solver finishes, review the result message and the worksheet values before accepting the solution. A feasible answer is not automatically a meaningful one: it still needs to satisfy the real-world interpretation of the model. Save a copy before major model changes so you can compare the prior setup if needed.

Frequently Asked Questions

Is there an Add Variable button in Excel Solver? No. Create a decision cell in the worksheet, then include it in the By Changing Variable Cells range in Solver Parameters. Solver treats the cells in that range as the values it is allowed to change.

How do I add a third variable to an existing Solver model? Put the third decision in a worksheet cell, expand the changing-cell range to include it, and update the objective and any constraint formulas affected by the new decision. Then check the limits and run Solver again.

Can Solver use cells that are not next to each other? Solver models are easiest to manage when decision cells are together in one continuous range. If your variables are scattered, consider reorganizing them into a contiguous block and adjusting formulas to refer to that block, which makes the changing-cell range easier to inspect.

Can Excel Solver change text or formula cells? Solver’s changing variables are numeric values, not text labels or formula cells. Put the adjustable numbers in decision cells and use separate cells with formulas to calculate profit, cost, or resource use.

Can I use Solver in Excel for the web? The desktop Solver add-in workflow is not available in Excel for the web. Open the workbook in desktop Excel for Microsoft 365 on Windows or Mac and enable the Solver add-in there.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.