Many a times as data analyst, we are doing scenario planning or simulation. Let’s say (simple example) we have a target of revenue of 200, fixed unit price of 5 and need to tell how many units need to be sold to achieve the targeted revenue. You must be thinking that it can be achieved by doing 200/5. But I’m using this as an example to start off and later will discuss more complex example which will difficult to manage with simple arithmetic formulas. Excel ha ms inbuilt goal seek function for this. Let’s discuss goal seek in excel.
How to use goal seek in excel
Goal Seek in Excel is a powerful tool that helps you find the optimal value for a variable that satisfies a specific condition. Here’s how to perform Goal Seek.
Method 1: Using the Goal Seek Dialog Box
- Select the cell containing the formula you want to adjust.
- Go to the “Data” tab in the ribbon.
- Click on “What-If Analysis” in the “Data Tools” group.
- Select “Goal Seek” from the drop-down menu.
- In the Goal Seek dialog box:
- Set cell: Select the cell containing the formula.
- To value: Enter the desired result.
- By changing cell: Select the cell you want to adjust.
- Click “OK” to run Goal Seek.
Method 2: Using the Shortcut
Select the cell containing the formula.
- Press Alt+A+W+G (Windows) or Command+Option+G (Mac).
An Example
Suppose you want to determine the interest rate required to achieve a monthly payment of $500 on a $20,000 loan with a 5-year term.
- Set up the formula:
=PMT(interest_rate, 60, 20000)
in cell A1. - Goal Seek:
- Set cell: A1
- To value: 500
- By changing cell: interest_rate (cell B1)
- Run Goal Seek.
Excel will adjust the interest rate in cell B1 to achieve the desired monthly payment of $500.
Few Tips and Variations
- Multiple variables: Goal Seek can adjust multiple variables simultaneously.
- Constraints: Use the “Solver” add-in for more complex optimization problems with constraints.
- Non-linear problems: Goal Seek may not work for non-linear problems; use the “Solver” add-in instead.
- Multiple solutions: Goal Seek may find multiple solutions; use the “Solver” add-in to explore alternative solutions.
Common Errors
- #NUM! error: Check for division by zero or invalid input.
- “No solution” error: Check for inconsistent or impossible goals.
There are few Alternative Tools that can be explored to solve such problems.
- Solver add-in (more advanced optimization capabilities)
- Scenario Manager (for exploring multiple scenarios)
- Sensitivity analysis (for analyzing how changes affect outcomes).
VBA macro code for Goal Seek in Excel
Simple Goal Seek:
MacroSub GoalSeekSimple() ' Declare variables Dim targetCell As Range Dim changingCell As Range Dim targetValue As Double ' Set target cell, changing cell, and target value Set targetCell = Range("A1") ' Cell containing formula Set changingCell = Range("B1") ' Cell to adjust targetValue = 500 ' Desired result ' Goal Seek Range(targetCell).GoalSeek GoalValue:=targetValue, ChangingCell:=changingCell End Sub
Advanced Goal Seek Macro with Error Handling:
Sub GoalSeekAdvanced() ' Declare variables Dim targetCell As Range Dim changingCell As Range Dim targetValue As Double Dim iterations As Long Dim tolerance As Double ' Set target cell, changing cell, and target value Set targetCell = Range("A1") ' Cell containing formula Set changingCell = Range("B1") ' Cell to adjust targetValue = 500 ' Desired result ' Set iterations and tolerance (optional) iterations = 100 tolerance = 0.01 ' Goal Seek with error handling On Error Resume Next Range(targetCell).GoalSeek GoalValue:=targetValue, ChangingCell:=changingCell, _ MaxIterations:=iterations, Tolerance:=tolerance If Err.Number <> 0 Then MsgBox "Goal Seek failed: " & Err.Description End If On Error GoTo 0 End Sub
How to Use:
- Open Excel and press
Alt + F11
to open VBA Editor. - Insert a new module (
Insert
> Module
). - Paste the code into the module.
- Update the target cell, changing cell, and target value variables.
- Run the macro (
F5
or Run
> Run Sub/UserForm
).
Tips and Variations:
- Use
Range
or Cells
to reference cells. - Adjust
iterations
and tolerance
for better convergence. - Use
Do...Loop
for iterative Goal Seek. - Integrate with other VBA macros or Excel formulas.
- Error handling:
On Error Resume Next
, Err.Number
, Err.Description
.
All the best.
Please follow and like us:
Like this:
Like Loading...
Related