Learning Outcomes
Learn relevant Excel functions
Set up linear programs in Excel
Solve linear programs in Excel
Excel Solver is a powerful tool for solving optimization problems with linear and nonlinear constraints. Before diving into using Solver, it is essential to understand some basic Excel functions and techniques that are commonly used when setting up optimization problems. These functions help organize data, compute intermediate values, and define objective functions and constraints.
Using Formulas in Cells In Excel, formulas begin with an equals sign (=). For example, typing =A1+B1 in a cell will calculate the sum of the values in cells A1 and B1.
SUM() The SUM() function adds a range of numbers. For example, =SUM(A1:A10) calculates the sum of all values in the range A1 to A10.
SUMPRODUCT() The SUMPRODUCT() function multiplies corresponding elements in two or more arrays and returns the sum of those products. This is particularly useful for computing dot products or weighted sums. For example, =SUMPRODUCT(A1:A10, B1:B10) computes .
COUNT() The COUNT() function counts the number of numeric entries in a range. For example, =COUNT(A1:A10) returns the number of numeric cells in the range A1 to A10.
COUNTIF() The COUNTIF() function counts the number of cells in a range that meet a specific condition. For example, =COUNTIF(A1:A10, ">5") counts the number of cells in A1:A10 with values greater than 5.
Duplicating Formulas Across Rows or Columns To apply a formula to multiple cells, you can drag the fill handle (a small square at the bottom-right corner of the selected cell) across the desired range. Excel automatically adjusts cell references based on the relative position (relative referencing). To keep a reference constant, use the dollar sign ($) in the cell reference (absolute referencing). For example, $A$1 always refers to cell A1.
Conditional Formatting Conditional formatting allows you to highlight cells that meet specific criteria. For example, you can format cells with values above a threshold in bold or a particular color to identify important data visually.
Data Validation Data validation helps restrict the type of data entered in a cell. For example, you can set a rule that only allows numbers within a specific range or text from a predefined list.
Naming Ranges Naming ranges makes formulas easier to read and maintain. Instead of =SUM(A1:A10), you can name the range "Sales" and write =SUM(Sales).
Using Logical Functions Logical functions like IF(), AND(), and OR() are helpful for decision-making within formulas. For example, =IF(A1>10, "High", "Low") returns “High” if A1 is greater than 10, and “Low” otherwise.
With these foundational tools, setting up optimization problems becomes much more manageable. In the next section, we will explore how to use these functions in combination with Excel Solver to define and solve optimization models.
Excel Solver is a powerful add-in that allows users to define and solve optimization problems. This section provides a step-by-step guide on how to effectively layout data and use Solver for optimization.
Step 1: Layout the Data Organizing your data clearly is crucial for using Solver effectively. Use color coding to distinguish between different types of cells:
Data: Cells containing fixed input values, such as coefficients or constants, should be highlighted in 50!white!//light blue.
Variables: Cells representing decision variables should be highlighted in yellow.
Formulas: Cells with formulas, such as the objective function or summarizing constraints values should be highlighted in 50!white!//light green.
Other color combinations are also acceptable, as long as they consistently distinguish between these components.
Step 2: Define the Objective Function Identify the cell that represents the objective function. This cell should contain a formula that calculates the value to be maximized or minimized, such as total profit or cost.
Step 3: Set Up Constraints Clearly specify the constraints of the problem. Constraints can be represented using formulas that involve the variables, coefficients, and right-hand side values. For example, a constraint ensuring that total production does not exceed capacity can be written as =SUMPRODUCT(Production, Coefficients) <= Capacity.
Step 4: Open Solver Ensure Solver is enabled in Excel. If not, you can activate it by navigating to File > Options > Add-Ins > Manage Excel Add-ins and checking the box for Solver.
Once Solver is enabled, go to Data > Solver to open the Solver
Parameters dialog box.
Step 5: Define Solver Parameters In the Solver Parameters dialog box:
Set the Objective to the cell containing the objective function.
Choose Max or Min to indicate whether the objective is to be maximized or minimized.
Specify the Variable Cells by selecting the range of cells representing decision variables.
Add Constraints by specifying the relationship (e.g., <=, >=, =) and the cells involved.
When the variables are non-negative, you can select Make Unconstrained Variables Non-Negative.
Step 6: Choose a Solving Method Solver provides three solving methods:
GRG Nonlinear: For smooth nonlinear problems.
Simplex LP: For linear programming problems.
Evolutionary: For non-smooth problems or those with integer constraints.
Select the method that matches the problem type.
Step 7: Solve the Problem Click Solve to run Solver. If Solver finds a solution, it will display the results and allow you to keep or discard them. Analyze the solution to ensure it meets the problem’s requirements.
Step 8: Interpret the Results Review the values of the decision variables and the objective function. Check that all constraints are satisfied and assess the solution’s feasibility and quality.
Resources
Examples and guides
Some videos
Some other links
Try it out visually!
Excel Solver Walkthrough: cells, formulas, and the Solver dialog on a small LP.
Exercise 3.1: Solver Rerun: Minimum-Cost Network Flow
This exercise mirrors Example 4.10 (Minimum-Cost Network Flow). Download the Excel workbook linked in that example and change only the cost data: shipping now costs per unit from Warehouse 1 to Store 1, from Warehouse 1 to Store 2, from Warehouse 2 to Store 1, and from Warehouse 2 to Store 2. The supplies ( and ), demands ( and ), and route capacities (, , , ) are unchanged.
Exercise 3.2: Solver Rerun: Production Planning over 10 Periods
This exercise mirrors Example 4.2 (Production Planning with 10 Periods). Download the Excel workbook linked in that example. Keep the production costs , the holding cost of , and the initial inventory , but replace the demands with .
Exercise 3.3: Diet Problem in Excel
A student on a tight budget is planning one day of meals from the five pantry staples below. The table gives the cost and nutrition data per serving.
|
| Price per serving | Calories per serving | Fat per serving | Protein per serving | Carbohydrate per serving |
| Oatmeal |
| 150 |
|
| 27 |
| Whole milk |
| 149 |
|
| 12 |
| Brown rice |
| 216 |
|
| 45 |
| Black beans |
| 227 |
| 15 | 41 |
| Almond butter |
| 196 | 18 |
| 6 |
Choose (possibly fractional) numbers of servings of each food so that the day’s totals satisfy all of the following requirements at the lowest possible grocery cost:
calories must be at least 2200,
fat must be at least ,
protein must be at least ,
carbohydrates must be at least .
Formulate the LP that finds the cheapest plan meeting every requirement.
Solve this problem using Excel Solver. Provide a screenshot of your spreadsheet with the optimal solution.
[§3.1]
Exercise 3.4: Production Planning in Excel
A small factory produces two products: widgets and gadgets. Each widget earns $8 in profit and each gadget earns $6. Production is limited by two resources:
| Widget | Gadget | Available | |
| Machine time (hrs) | 2 | 1 | 40 |
| Raw material (kg) | 1 | 2 | 30 |
Both products require nonnegative production quantities.
[§3.1]
Exercise 3.5: Transportation Problem in Excel
A company has two warehouses (W1 and W2) that supply three retail stores (S1, S2, S3). The shipping cost per unit, supply at each warehouse, and demand at each store are given below:
| S1 | S2 | S3 | Supply | |
| W1 | $4 | $8 | $1 | 60 |
| W2 | $6 | $3 | $5 | 50 |
| Demand | 30 | 40 | 40 | |
Exercise 3.6: Product Mix with a Sensitivity Report
A furniture shop makes tables, chairs, and desks with profits of $70, $50, and $90 per item. Weekly resources are 240 hours of carpentry, 100 hours of finishing, and 2000 board-feet of wood:
| Table | Chair | Desk | Available | |
| Carpentry (hrs) | 4 | 3 | 6 | 240 |
| Finishing (hrs) | 2 | 1 | 3 | 100 |
| Wood (bd-ft) | 30 | 20 | 40 | 2000 |
Production quantities may be fractional.
[§3.1]
Exercise 3.7: Unbalanced Transportation with a Sensitivity Report
Three plants supply three cities. Plant capacities are 70, 50, and 40 units; city demands are 50, 60, and 40 units, so total supply exceeds total demand. Shipping costs per unit are:
| C1 | C2 | C3 | Supply | |
| P1 | $4 | $5 | $7 | 70 |
| P2 | $6 | $3 | $2 | 50 |
| P3 | $5 | $8 | $4 | 40 |
| Demand | 50 | 60 | 40 | |
Exercise 3.8: Simplex LP versus GRG Nonlinear
Solver’s dialog offers three solving methods: Simplex LP, GRG Nonlinear, and Evolutionary.
[§3.1]
Exercise 3.9: When a Variable Must Go Negative
An investor has $100 (in thousands) to split between fund A, which returns 5%, and fund B, which returns 12%. The broker allows short selling fund A: the investor may hold a negative amount of A and use the proceeds to buy more of B. Margin rules cap the holding in B at $140. The model is
[§3.1]
Solution
(Exercise 3.4) Let and be the number of widgets and gadgets produced. The LP behind the spreadsheet is
In Excel, put the two variables in yellow cells, compute the objective and the two constraint left-hand sides with SUMPRODUCT in green cells, and add the constraints in Solver with the Simplex LP method. Solver returns widgets and gadgets with maximum profit ; both resource constraints are binding. For part 3, the Sensitivity Report shows the allowable increase for the widget profit coefficient. Raising it from $8 to $9 stays within the allowable range, so the optimal production plan does not change — only the profit does, rising to $190. (Geometrically, the objective slope stays between the slopes of the two binding constraints, so the same corner point remains optimal.)
Solution
(Exercise 3.5) Let be the number of units shipped from warehouse to store . A natural Excel layout is a grid of yellow variable cells mirroring the cost table, with row sums compared to supply and column sums compared to demand:
Total supply equals total demand (110 units), so both supplies are used fully. Solver finds the optimal plan , , , (all other routes unused), with minimum cost $300: each warehouse ships everything it can along its cheapest routes (W1 to S3, W2 to S2), and store S1’s demand is split to make the supplies balance.
Solution
(Exercise 3.9) With the checkbox checked, Solver silently adds and , so the best it can do is , , for a return of (that is, $12,000). With the checkbox unchecked and added as an explicit constraint, Solver finds , : the investor shorts $40 of fund A to push fund B to its margin cap, earning , or $14,800. The checkbox applies a lower bound of zero to every decision variable that has no explicit lower bound in the constraint list. Short selling is exactly a negative holding, so that hidden bound cuts off the optimal solution. The risk when unchecking is that all other variables also lose the automatic bound: any variable that should be non-negative (here ) must now get its own constraint, or Solver may return meaningless negative values for it.