- Ablebits blog
- Financial functions
How to use Solver in Excel with examples
The tutorial explains how to add and where to find Solver in different Excel versions, from 2016 to 2003. Step-by-step examples show how to use Excel Solver to find optimal solutions for linear programming and other kinds of problems.
Everyone knows that Microsoft Excel contains a lot of useful functions and powerful tools that can save you hours of calculations. But did you know that it also has a tool that can help you find optimal solutions for decision problems?
In this tutorial, we are going to cover all essential aspects of the Excel Solver add-in and provide a step-by-step guide on how to use it most effectively.
What is Excel Solver?
Excel Solver belongs to a special set of commands often referred to as What-if Analysis Tools. It is primarily purposed for simulation and optimization of various business and engineering models.
The Excel Solver add-in is especially useful for solving linear programming problems, aka linear optimization problems, and therefore is sometimes called a linear programming solver . Apart from that, it can handle smooth nonlinear and non-smooth problems. Please see Excel Solver algorithms for more details.
How to add Solver to Excel
The Solver add-in is included with all versions of Microsoft Excel beginning with 2003, but it is not enabled by default.
To add Solver to your Excel, perform the following steps:
- In Excel 2010 - Excel 365, click File > Options . In Excel 2007, click the Microsoft Office button, and then click Excel Options .
To get Solver on Excel 2003 , go to the Tools menu, and click Add-Ins . In the Add-Ins available list, check the Solver Add-in box, and click OK .
Where is Solver in Excel?
Where is Solver in Excel 2003?
Now that you know where to find Solver in Excel, open a new worksheet and let's get started!
How to use Solver in Excel
Before running the Excel Solver add-in, formulate the model you want to solve in a worksheet. In this example, let's find a solution for the following simple optimization problem.
Problem . Supposing, you are the owner of a beauty salon and you are planning on providing a new service to your clients. For this, you need to buy a new equipment that costs $40,000, which should be paid by instalments within 12 months.
Goal : Calculate the minimal cost per service that will let you pay for the new equipment within the specified timeframe.
And now, let's see how Excel Solver can find a solution for this problem.
1. Run Excel Solver
2. define the problem.
The Solver Parameters window will open where you have to set up the 3 primary components:
- Objective cell
Variable cells
Constraints.
Exactly what does Excel Solver do with the above parameters? It finds the optimal value (maximum, minimum or specified) for the formula in the Objective cell by changing the values in the Variable cells, and subject to limitations in the Constraints cells.
The Objective cell ( Target cell in earlier Excel versions) is the cell containing a formula that represents the objective, or goal, of the problem. The objective can be to maximize, minimize, or achieve some target value.
Variable cells ( Changing cells or Adjustable cells in earlier versions) are cells that contain variable data that can be changed to achieve the objective. Excel Solver allows specifying up to 200 variable cells.
In this example, we have a couple of cells whose values can be changed:
- Projected clients per month (B4) that should be less than or equal to 50; and
- Cost per service (B5) that we want Excel Solver to calculate.
The Excel Solver Constrains are restrictions or limits of the possible solutions to the problem. To put it differently, constraints are the conditions that must be met.
To add a constraint(s), do the following:
- Click the Add button right to the " Subject to the Constraints " box.
- In the Constraint window, enter a constraint.
- Click the Add button to add the constraint to the list.
- Continue entering other constraints.
- After you have entered the final constraint, click OK to return to the main Solver Parameters window.
Excel Solver allows specifying the following relationships between the referenced cell and the constraint.
- Less than or equal to , equal to , and greater than or equal to . You set these relationships by selecting a cell in the Cell Reference box, choosing one of the following signs: <= , =, or >= , and then typing a number, cell reference / cell name, or formula in the Constraint box (please see the above screenshot).
- Integer . If the referenced cell must be an integer, select int , and the word integer will appear in the Constraint box.
- Different values . If each cell in the referenced range must contain a different value, select dif , and the word AllDifferent will appear in the Constraint box.
- Binary . If you want to limit a referenced cell either to 0 or 1, select bin , and the word binary will appear in the Constraint box.
To edit or delete an existing constraint do the following:
- In the Solver Parameters dialog box, click the constraint.
- To modify the selected constraint, click Change and make the changes you want.
- To delete the constraint, click the Delete button.
In this example, the constraints are:
- B3=40000 - cost of the new equipment is $40,000.
- B4<=50 - the number of projected patients per month in under 50.
3. Solve the problem
After you've configured all the parameters, click the Solve button at the bottom of the Solver Parameters window (see the screenshot above) and let the Excel Solver add-in find the optimal solution for your problem.
Depending on the model complexity, computer memory and processor speed, it may take a few seconds, a few minutes, or even a few hours.
The Solver Result window will close and the solution will appear on the worksheet right away.
- If the Excel Solver has been processing a certain problem for too long, you can interrupt the process by pressing the Esc key. Excel will recalculate the worksheet with the last values found for the Variable cells.
- To get more details about the solved problem, click a report type in the Reports box, and then click OK . The report will be created on a new worksheet:
Excel Solver examples
Below you will find two more examples of using the Excel Solver addin. First, we will find a solution for a well-known puzzle, and then solve a real-life linear programming problem.
Excel Solver example 1 (magic square)
I believe everyone is familiar with "magic square" puzzles where you have to put a set of numbers in a square so that all rows, columns and diagonals add up to a certain number.
For instance, do you know a solution for the 3x3 square containing numbers from 1 to 9 where each row, column and diagonal adds up to 15?
It's probably no big deal to solve this puzzle by trial and error, but I bet the Solver will find the solution faster. Our part of the job is to properly define the problem.
With all the formulas in place, run Solver and set up the following parameters:
- Set Objective . In this example, we don't need to set any objective, so leave this box empty.
- Variable Cells . We want to populate numbers in cells B2 to D4, so select the range B2:D4.
- $B$2:$D$4 = AllDifferent - all of the Variable cells should contain different values.
- $B$2:$D$4 = integer - all of the Variable cells should be integers.
- $B$5:$D$5 = 15 - the sum of values in each column should equal 15.
- $E$2:$E$4 = 15 - the sum of values in each row should equal 15.
- $B$7:$B$8 = 15 - the sum of both diagonals should equal 15.
Excel Solver example 2 (linear programming problem)
This is an example of a simple transportation optimization problem with a linear objective. More complex optimization models of this kind are used by many companies to save thousands of dollars each year.
Problem : You want to minimize the cost of shipping goods from 2 different warehouses to 4 different customers. Each warehouse has a limited supply and each customer has a certain demand.
Goal : Minimize the total shipping cost, not exceeding the quantity available at each warehouse, and meeting the demand of each customer.
Source data
Formulating the model
To define our linear programming problem for the Excel Solver, let's answer the 3 main questions:
- What decisions are to be made? We want to calculate the optimal quantity of goods to deliver to each customer from each warehouse. These are Variable cells (B7:E8).
- What are the constraints? The supplies available at each warehouse (I7:I8) cannot be exceeded, and the quantity ordered by each customer (B10:E10) should be delivered. These are Constrained cells .
- What is the goal? The minimal total cost of shipping. And this is our Objective cell (C12).
To make our transportation optimization model easier to understand, create the following named ranges:
The last thing left for you to do is configure the Excel Solver parameters:
- Objective: Shipping_cost set to Min
- Variable cells: Products_shipped
- Constraints: Total_received = Ordered and Total_shipped <= Available
How to save and load Excel Solver scenarios
When solving a certain model, you may want to save your Variable cell values as a scenario that you can view or re-use later.
For example, when calculating the minimal service cost in the very first example discussed in this tutorial, you may want to try different numbers of projected clients per month and see how that affects the service cost. At that, you may want to save the most probable scenario you've already calculated and restore it at any moment.
Saving an Excel Solver scenario boils down to selecting a range of cells to save the data in. Loading a Solver model is just a matter of providing Excel with the range of cells where your model is saved. The detailed steps follow below.
Saving the model
To save the Excel Solver scenario, perform the following steps:
- Open the worksheet with the calculated model and run the Excel Solver.
- Excel will save your current model, which may look something similar to this:
Loading the saved model
When you decide to restore the saved scenario, do the following:
- In the Solver Parameters window, click the Load/Save button.
- This will open the main Excel Solver window with the parameters of the previously saved model. All you need to do is to click the Solve button to re-calculate it.
Excel Solver algorithms
When defining a problem for the Excel Solver, you can choose one of the following methods in the Select a Solving Method dropdown box:
- GRG Nonlinear. Generalized Reduced Gradient Nonlinear algorithm is used for problems that are smooth nonlinear, i.e. in which at least one of the constraints is a smooth nonlinear function of the decision variables. More details can be found here .
- LP Simplex . The Simplex LP Solving method is based the Simplex algorithm created by an American mathematical scientist George Dantzig. It is used for solving so called Linear Programming problems - mathematical models whose requirements are characterized by linear relationships, i.e. consist of a single objective represented by a linear equation that must be maximized or minimized. For more information, please check out this page .
- Evolutionary . It is used for non-smooth problems, which are the most difficult type of optimization problems to solve because some of the functions are non-smooth or even discontinuous, and therefore it's difficult to determine the direction in which a function is increasing or decreasing. For more information, please see this page .
This is how you can use Solver in Excel to find the best solutions for your decision problems. At the end of this post, you can download the sample workbook with all the examples discussed in this tutorial and reverse-engineer them for better understanding. I thank you for reading and hope to see you on our blog next week.
Practice workbook for download
You may also be interested in.
- Using Excel Goal Seek for What-If analysis
- Excel Copilot with examples
- Linear regression analysis in Excel
- Microsoft Excel formulas with examples
- How to use VLOOKUP & SUM or SUMIF functions in Excel
Table of contents
51 comments
If you change the constraint on the Magic Square sum to be -15 instead of 15, all the solvers choke. I'm not sure why. It says that the constraints are not met, but I can't see where there is a constraint for any of the numbers to be positive. Any ideas?
Hello Matt! The information you have provided is not enough to understand the problem and give you advice.
How can someone develop further by adding additional constraint (Carbon tax) to already solved transshipment problem?
Hi! Product and pricing information is available from this link at the top of any page on the site.
You decide to include the cost of making the combo as you purchase from different suppliers. The packaging costs vary between R25 and R15. Determine how many units you need to sell daily to still get a profit of R18 000 at each varying packaging cost when selling the combo at R55 each. Use the Solver function.
All the information you need to solve this task is in the article above.
Post a comment
IMAGES
VIDEO