Sub topic 13
Keeping solved models reliable: hardcodes, circularity, scaling, and checks
This chapter assumes you can run Goal Seek and Solver, you know what an objective cell and a changing cell are, and you have read Solver's result messages. Here the question is whether the answer can be trusted and whether it will still be correct next week.
A solved model has a weakness that an ordinary model does not. A tool has overwritten an input with a number it found by trial. That number is only as good as the model's structure, the solver settings, and your discipline in checking it.
Hardcodes: the most common silent failure
A hardcode is a typed number where a formula or an input-cell reference should be. Target-seeking exposes hardcodes because the search relies on a live chain of dependencies from the changing cell to the target cell. Break the chain anywhere and the tool searches in vain.
Where hardcodes cause trouble
- A constant inside a formula. If the profit formula is
=B1*(50-30)-15000, then changing the price in B2 does nothing. Goal Seek on B2 will fail or wander. - A pasted value in the chain. Someone pastes values over a calculated revenue row. The target cell no longer depends on your changing cell.
- A formula in the changing cell. Goal Seek requires the changing cell to hold a value. If it holds a formula, Excel stops with a "Cell must contain a value" error. Solver also needs variable cells to be inputs, not formulas.
- A solved value that looks like an assumption. After Goal Seek runs, B1 holds 750. Nothing tells the next reader that 750 is an output of a search and not an input someone chose.
How to find them
- Use Home > Find & Select > Go To Special > Constants on the calculation area. Any constant in a region that should be all formulas needs an explanation.
- Use Formulas > Show Formulas (Ctrl+`) and scan for formulas containing literal numbers.
- Select the target cell and use Trace Precedents (Ctrl+[ jumps to them). Confirm that the changing cell appears upstream.
- Run a sensitivity test: change the changing cell by hand, and confirm that the target cell moves.
How to label solved inputs
Keep the solved input in the inputs section and mark it. For example, put a note in the adjacent column such as "Solved by Goal Seek to make B5 = 0; rerun after changing assumptions". Better, keep the original assumption in one cell and the solved value in another, with a switch that chooses which one feeds the model. Then you can always get back to the unsolved case.
Circularity and iterative calculation
A circular reference exists when a formula depends, directly or through a chain, on its own result. The classic financial example is interest on average debt. Interest depends on the ending balance, and the ending balance depends on interest.
Excel can tolerate this if you enable File > Options > Formulas > Enable iterative calculation. It then recalculates up to Maximum Iterations times, stopping when changes fall below Maximum Change. Defaults are 100 and 0.001.
Circularity interacts badly with target-seeking:
- Each Goal Seek or Solver trial triggers a full iterative recalculation. The result is slower runs.
- Goal Seek's own stopping accuracy is governed by the same Maximum Change setting. A loose setting can make Goal Seek report success when the target is still visibly off.
- If the circular loop diverges or produces an error such as
#NUM!, the error propagates into the target cell. Errors persist in the loop even after the cause is fixed. The search then fails every trial. - Results can depend on the starting state of the loop, so the same solve gives slightly different answers on different runs.
Options for handling it
| Approach | How | Trade-off |
|---|---|---|
| Remove the circularity | Compute interest on the opening balance, or solve the loop algebraically | Simple and stable, but slightly less precise |
| Circuit breaker | A 1/0 switch cell: `=IF(Switch=1, interest_formula, 0)` | Lets you clear errors by flipping the switch off and on |
| Keep it, tighten settings | Reduce *Maximum Change* (for example to 0.00001) | Slower, and still requires checks |
The algebraic route is worth knowing, because it shows that a circular reference is an equation. This Python snippet solves interest on average balance by iteration and by closed form, so you can see they agree.
begin = 1000.0
shortfall = 200.0
rate = 0.08
# Fixed-point iteration: what Excel's iterative calculation does.
end_bal = begin
for _ in range(100):
interest = rate * (begin + end_bal) / 2
new_end = begin + shortfall + interest
if abs(new_end - end_bal) < 1e-9:
break
end_bal = new_end
# Closed form: end = begin + shortfall + rate*(begin + end)/2, solved for end.
closed = (begin * (1 + rate / 2) + shortfall) / (1 - rate / 2)
print(round(end_bal, 4), round(closed, 4))Both values are 1291.6667. In a worksheet, the closed-form formula removes the loop, so Goal Seek and Solver run on a model that needs no iterative calculation.
Scaling: when units are the problem
Numerical search works with differences between trial results. If the numbers involved differ by many orders of magnitude, the search handles them poorly.
Typical scaling problems:
- A target of 0 in a profit cell measured in dollars. A residual of 0.004 is a fine answer to Goal Seek's tolerance, yet the same tolerance applied to a model in millions leaves an error of about $4,000.
- Solver variables such as a growth rate near 0.05 beside a capital amount near 5,000,000. Steps that suit one are useless for the other.
- Constraints compared at very different magnitudes, such as
cash >= 0where cash is in millions and a ratio must stay below 0.35.
Practical remedies
- Put the model in consistent, sensible units, for example thousands or millions of dollars, and label them.
- In Solver, tick Use Automatic Scaling under Options when using GRG Nonlinear.
- Give Solver sensible starting values, near the likely answer and not at 0. A start at exactly 0 can put the search on a flat or undefined area, for example when a rate feeds a division.
- Set explicit bounds on every variable. Bounds keep the search in a region where the model is valid.
- Define the Goal Seek target in a way that makes the tolerance meaningful. Solve for a difference cell,
=Actual - Target, to 0, and check that cell in the same units you report.
Checks that prove the answer
A solver status of "found a solution" says the algorithm met its stopping rules. It does not say your model is right. Build checks so that every solved result can be judged without trusting the tool.
A check block
Put a small block beside the model, with formulas that return TRUE or FALSE.
| Check | Example formula | Purpose |
|---|---|---|
| Target met | `=ABS(B5)<0.01` | The residual is within a tolerance you chose |
| Input in range | `=AND(B1>=0, B1<=10000)` | The solved input is plausible |
| Balance sheet balances | `=ABS(Assets-LiabEquity)<0.01` | No structural error exposed by the solved input |
| Constraints satisfied | `=AND(hours<=100, units<=40)` | Solver's answer respects business rules |
| No errors | `=NOT(ISERROR(B5))` | Calculation chain is intact |
Tie them into one master cell, such as =AND(C2:C6), and show it near the top of the model. Check cells make a failed or stale solve visible.
Independent verification
- Plug it back in. Type the solved value into a copy of the model and confirm the target by hand.
- Restart from elsewhere. Run Goal Seek or Solver from two different starting values. If they give different answers, there are multiple solutions or a flat region, and you need to choose between them deliberately.
- Recompute outside Excel. For the break-even model,
brentqshould return about 750:
from scipy.optimize import brentq
def profit(units):
return units * (50 - 30) - 15000
print(round(brentq(profit, 0, 10000), 2))- Look at binding constraints. In a Solver result, check which constraints are binding (at their limit). If a constraint you did not expect is binding, the model or the constraint may be wrong.
- Perturb the answer. Move the solved input slightly each way. If the target changes sharply, the answer is fragile.
Guarding a macro
When you automate Goal Seek, save the original value and restore it on failure. This prevents a failed search from leaving a half-solved value in the model.
Sub SolveBreakEvenSafely()
Dim original As Double
Dim ok As Boolean
original = Range("B1").Value
ok = Range("B5").GoalSeek(Goal:=0, ChangingCell:=Range("B1"))
If Not ok Or Abs(Range("B5").Value) > 0.01 Then
Range("B1").Value = original
MsgBox "No valid solution found. Original input restored."
End If
End SubPutting it together
A solved input is a snapshot. When any assumption changes, the old answer is stale, and the model will not warn you unless a check cell does. Your check block's "Target met" cell is that warning: after an assumption changes, it turns FALSE until you rerun the search.
Common mistakes
- Accepting "Solver found a solution" without looking at the constraints and the target cell.
- Running Goal Seek on a changing cell that feeds nothing, then trusting the unchanged value.
- Leaving iterative calculation on with a loop nobody intended.
- Solving a model in raw dollars with default tolerances and reporting figures at a precision the search never reached.
- Overwriting the original assumption with the solved value and losing the base case.
Exercise
A colleague's Goal Seek on a loan model returns "found a solution," but the payment cell still shows $412 when the target was $400. The model has iterative calculation on, with Maximum Change at 0.001 and a circular interest formula. Name two likely causes and one check you would run.
Show answer
Likely causes: (1) the changing cell does not actually feed the payment cell, because of a hardcode or a pasted value in the chain, so the target cell never responds. (2) The circular loop has not converged, or its tolerance is too loose or too unstable for the search to settle. Check: trace precedents from the payment cell to confirm the changing cell is upstream, then type a different value in the changing cell and see whether the payment moves. A "Target met" check cell such as =ABS(Payment-400)<0.01 would also flag the failure immediately.
Exercise
Explain why a solved model's changing cell should be kept apart from the original assumption, and describe one way to set that up.
Show answer
Goal Seek and Solver overwrite the changing cell with a found value, which erases the original assumption and makes the solved number look like a chosen input. Keep the original assumption in one cell and the solved value in another, and use a 1/0 switch cell with =IF(Switch=1, Solved, Original) in the cell that feeds the model. You can then return to the base case by flipping the switch, and a label beside the solved cell records the target, the date, and the tool used.