Sub topic 8
Clearing errors stuck in the loop
This chapter assumes you have a debt schedule with average-balance interest, iterative calculation turned on, and a circuit-breaker cell named Circ_Switch. The formulas follow the earlier chapters.
Why an error stays after you fix its cause
In an ordinary spreadsheet, an error disappears once you fix its source. A circular loop behaves differently. The loop is a chain in which each cell reads the previous one, and the last cell feeds the first.
Interest: =IF(Circ_Switch=1, Rate*AVERAGE(Debt_Open, Debt_Close), Rate*Debt_Open)
Repayment: =MIN(Debt_Open, MAX(0, CFADS - Interest))
Debt_Close: =Debt_Open - RepaymentSuppose CFADS briefly returns #DIV/0! because an input was blank. Repayment becomes #DIV/0!, so Debt_Close becomes #DIV/0!, so Interest becomes #DIV/0!. You then repair the input and CFADS is a number again. On the next iteration, Repayment still reads Interest, and Interest is still an error. Each cell is an error because the cell before it is an error, so the loop sustains itself with no cell left to start the recovery.
Any arithmetic that touches an error returns an error. That is why fixing the original cause is necessary but not sufficient. You also have to flush the loop.
How errors enter a circular model
Errors rarely start inside the loop. They arrive from outside it and then get trapped. The common entry points are:
| Source | Typical error | Why it happens |
|---|---|---|
| Blank or zero denominator in a ratio feeding `CFADS` | `#DIV/0!` | A cell like margin or days is empty during a scenario switch |
| Lookup returning no match | `#N/A` | A scenario or date index is missing a row |
| Text in a numeric cell | `#VALUE!` | A pasted value or a stray label is read as an input |
| Deleted or moved reference | `#REF!` | A row is removed in the debt schedule |
| Overflow in an unstable iteration | `#NUM!` | The loop diverges and produces numbers too large to store |
| Iterative calculation disabled mid-session | Circular reference warning, zeros | The setting is a property of the application session, so another open workbook can change it |
The last row is not an error value, but it causes the same confusion. Excel applies the iterative setting from the first workbook opened in a session. If you open your model after another workbook with iteration off, the loop stops solving, and you will see warnings and stale numbers.
The standard recovery: use the breaker
The circuit-breaker is the main tool for clearing a trapped error. It works because, with Circ_Switch set to 0, Interest no longer reads Debt_Close. The loop is cut, and Interest depends only on Debt_Open, which does not depend on the loop.
Follow this sequence:
- Fix the external cause first. Find the broken input, lookup or reference and repair it.
- Set
Circ_Switchto 0.Interestnow equalsRate*Debt_Open, which is a clean number ifDebt_Openis clean. - Let the model recalculate.
Repayment,Debt_Closeand everything downstream become numbers again. - Check that no error remains anywhere in the workbook.
- Set
Circ_Switchback to 1. Iteration starts from clean values and converges.
If you skip step 1, step 5 reintroduces the error and the loop traps it again.
Seeing it in a small simulation
A spreadsheet's iteration is hard to watch, so this Python script reproduces the trapped error. It uses the same numbers as earlier chapters: opening debt of 500, cash flow of 100, a rate of 8%. The script leaves out the MIN and MAX clamps on purpose. Python's max(0, nan) silently returns 0, which would hide the problem, whereas Excel passes the error through.
import math
def one_pass(opening, cfads, rate, interest, circ_switch):
closing = opening - (cfads - interest)
if circ_switch == 1:
return rate * (opening + closing) / 2
return rate * opening
opening, cfads, rate = 500.0, 100.0, 0.08
# An error enters the loop from outside (nan stands in for #DIV/0!).
interest = float("nan")
# Switch on: the error feeds itself, even though the inputs are now fine.
for _ in range(20):
interest = one_pass(opening, cfads, rate, interest, 1)
print("switch on, poisoned:", interest, math.isnan(interest))
# Switch off: interest depends only on the opening balance.
for _ in range(20):
interest = one_pass(opening, cfads, rate, interest, 0)
print("switch off:", interest)
# Switch back on: iteration restarts from a clean number and converges.
for _ in range(50):
interest = one_pass(opening, cfads, rate, interest, 1)
print("switch on again:", round(interest, 4))The script prints nan while the loop is poisoned, then 40.0 with the breaker off, then 37.5 once the loop is closed again. The 40.0 is simply 0.08 * 500. The restart from 40.0 converges to 37.5 because each pass shrinks the remaining error by a factor of rate / 2, which is 0.04.
Finding the cell that started it
Clearing the loop is only half the job. You also need to know why the error appeared, or it will return. Use these techniques, in this order:
- Switch the breaker to 0 and scan for remaining errors. With the loop cut, anything still showing an error is not caused by the loop. Those cells are your true sources.
- Use Go To Special. Press F5, choose Special, then Formulas, and tick only Errors. Excel selects every cell currently showing an error. Move through the selection and look for the cell furthest upstream.
- Trace precedents. On the Formulas tab, Trace Precedents draws arrows to the cells a formula reads. Follow them until you find a cell whose inputs are all clean but which shows an error. That cell is the origin.
- Evaluate Formula. For a long formula, step through it with Evaluate Formula to see which sub-expression fails.
- Check inputs, not just calculations. A single blank input, a text value or a deleted row accounts for most cases.
Excel's error checking can also help. The Formulas tab has an Error Checking command, and its Circular References submenu lists the cells Excel considers part of a loop.
Guards that make the loop self-healing
You can reduce how often you need manual recovery by building the guard into the formula. A common pattern wraps the loop-closing term in IFERROR, so a failed read returns zero instead of an error:
Interest: =IF(Circ_Switch=1, IFERROR(Rate*AVERAGE(Debt_Open, Debt_Close), 0), Rate*Debt_Open)
Loop_Error: =IF(ISERROR(Debt_Close), 1, 0)With this version, a trapped error resets Interest to 0 on the next pass, and the loop recovers by itself as soon as the cause is fixed.
A second protection costs nothing: a cell that shows the number of iterations or the change between the last two passes. If the change is stuck at an error or growing, you know before you read the outputs.
Errors that look like trapped errors but are not
Not every strange value in a circular model is a stuck error. Check these cases before you reach for the breaker:
- Zero interest and zero repayment everywhere. Iteration is probably disabled. Check File, Options, Formulas, and confirm Enable iterative calculation is ticked. Check also that no other open workbook turned it off.
- Numbers that move slightly on every recalculation. The iteration has not converged. The maximum change setting may be too loose, or the maximum iterations too low. This needs a tighter tolerance or more passes, not a breaker reset.
- Numbers that grow without limit. The loop is diverging. This usually means a sign error, for example interest added to cash instead of subtracted, or a rate far above 100%. Resetting the breaker will not help until you fix the formula.
- Different results each time you open the file. The loop may be converging to different values because the starting values differ, or because manual calculation mode left some cells stale. Press F9 until values settle, then check.
Recovery checklist
Use this list when you hand the model to someone else, or when you return to it after a break:
- Does
Circ_Switchequal 1 in the version you intend to use? - Is iterative calculation on in the session where you are working?
- Do all model checks show zero errors, including the loop-error flag?
- Does the interest in the final period match
Ratetimes the average of opening and closing debt, to within your tolerance? - Do the balance sheet and cash flow statement still balance?
The last two checks lead into the next chapters on validating circular solutions.
Exercise
A debt schedule shows #DIV/0! in Interest, Repayment and Debt_Close. You find that a blank input cell caused the problem and you fill it in, but the errors remain. Explain why they remain, and list the steps to recover.
Show answer
The error is stored inside the loop. Interest reads Debt_Close, Debt_Close reads Repayment, and Repayment reads Interest, so each cell is an error because the previous one is an error. Fixing the input does not change the stored values. To recover, set Circ_Switch to 0 so Interest uses only Debt_Open and the loop is cut, let the model recalculate, confirm no errors remain, and then set Circ_Switch back to 1 so iteration restarts from clean numbers.
Exercise
With the breaker on, opening debt is 500, cash flow is 100 and the rate is 8%. You reset the loop through the breaker, so the first clean interest figure is 40.0 (breaker off). By what factor does the remaining error shrink on each pass once the breaker is back on, and what value does interest settle at?
Show answer
Each pass multiplies the remaining error by rate / 2, which is 0.04. Interest settles at 37.5, where it equals 0.08 * (500 + 437.5) / 2.
Exercise
A colleague wraps the whole Repayment formula in IFERROR(..., 0) to stop errors from sticking. Give one benefit and one risk of this approach.
Show answer
The benefit is that the loop recovers automatically, because a failed read returns 0 and the next pass starts from a number. The risk is that a real mistake, such as a broken reference, is hidden: repayments show 0 and the model looks plausible but is wrong. The guard should sit only on the loop-closing term and be paired with a visible error flag.