Sub topic 3
Clearing Errors Stuck in the Loop
This chapter assumes you have built a debt schedule with a cash sweep, that you use average-balance interest, and that you know how to turn on iterative calculation in your spreadsheet.
When an error such as #VALUE! or #DIV/0! enters a circular loop, it feeds itself. Each recalculation passes the error from interest to repayment to closing balance and back to interest, so the error never clears on its own, even after you fix the input that caused it.
To clear it, set the circuit-breaker switch (Circ_Switch) to 0, recalculate, and confirm the errors are gone. Then set the switch back to 1.
Removing the Loop with Algebra
For a simple sweep, you can solve the loop directly. With interest = rate × (opening + closing) / 2 and closing = opening − CFADS + interest, the equation becomes linear:
def solve_interest(opening, cfads, rate):
interest = rate * (2 * opening - cfads) / 2 / (1 - rate / 2)
closing = opening - cfads + interest
return interest, closing
print(solve_interest(500.0, 100.0, 0.08)) # (37.5, 437.5)This formula holds only when neither MIN nor MAX limits on repayment are active.
The Copy-Paste Macro Alternative
A macro can copy the closing-balance values and paste them as hard-coded numbers, which breaks the loop. It then repeats until the values stop changing. This avoids iterative settings but adds a macro you must maintain, so use it only when your team cannot enable iterative calculation.
Checking That the Circular Solution Is Consistent
Confirm these checks after every change:
- Closing balance equals opening balance minus repayment.
- Interest equals rate × average balance, within a small tolerance.
- The change between iterations is below your tolerance.
Choosing the Right Approach for Your Model
| Approach | Use when |
|---|---|
| Opening-balance interest | Precision loss is acceptable and you want no circularity |
| Iterative calculation with breaker | Average-balance interest is required and the model is complex |
| Algebraic solution | The sweep is simple and no MIN or MAX limits bind |
| Copy-paste macro | Iterative calculation is not allowed in your environment |
Exercise
The loop shows #VALUE! in every cell. What is the first step?
Show answer
Set CircSwitch to 0, recalculate, and confirm the errors clear. Then set CircSwitch back to 1.