Sub topic 10
The Copy-Paste Macro Alternative
Prerequisites and the basic idea
Assume you can build a debt schedule with cash flow available for debt service (CFADS), interest, repayment, and closing debt. You should also be comfortable with Excel formulas such as MIN, MAX, and AVERAGE.
A copy-paste macro solves circularity by separating the interest guess from the interest calculation. The macro writes a guessed interest amount into a cell, recalculates the debt schedule, reads the resulting interest, and writes that result back as the next guess. It repeats until the change is small enough.
The worksheet does not contain a circular formula. Instead, the macro performs the repeated calculation externally.
Set up the worksheet
On a worksheet named Debt, use this simple layout:
| Cell | Meaning | Example |
|---|---|---|
| B2 | Opening debt | 500 |
| B3 | CFADS before interest | 100 |
| B4 | Interest rate | 8% |
| B5 | Interest guess and final interest | 0 |
| B6 | Repayment | formula |
| B7 | Closing debt | formula |
| B8 | Recomputed interest | formula |
The formulas in B6:B8 are deliberately one-way:
B6: repayment equals the lesser of opening debt and cash remaining after interest.B7: closing debt equals opening debt less repayment.B8: interest equals the rate multiplied by the average of opening and closing debt.
The macro changes B5 from one iteration to the next.
Option Explicit
Sub SolveDebtInterest()
Dim ws As Worksheet
Dim guess As Double
Dim newInterest As Double
Dim tolerance As Double
Dim maxIterations As Long
Dim iteration As Long
Set ws = ThisWorkbook.Worksheets("Debt")
tolerance = 0.000001
maxIterations = 100
guess = 0#
ws.Range("B6").Formula = "=MIN(B2,MAX(0,B3-B5))"
ws.Range("B7").Formula = "=B2-B6"
ws.Range("B8").Formula = "=B4*AVERAGE(B2,B7)"
For iteration = 1 To maxIterations
ws.Range("B5").Value = guess
ws.Range("B6:B8").Calculate
newInterest = CDbl(ws.Range("B8").Value)
If Abs(newInterest - guess) < tolerance Then
ws.Range("B5").Value = newInterest
ws.Range("B6:B8").Calculate
MsgBox "Converged in " & iteration & _
" iterations. Interest = " & _
Format(newInterest, "0.0000"), vbInformation
Exit Sub
End If
guess = newInterest
Next iteration
MsgBox "The calculation did not converge within " & _
maxIterations & " iterations.", vbExclamation
End SubWith the example inputs, the macro converges to interest of approximately 37.5 and closing debt of approximately 437.5.
What the macro is doing
The first pass uses zero interest:
- B5 contains 0.
- The repayment and closing debt formulas calculate from that guess.
- B8 calculates interest using the new closing debt.
- The macro copies B8's value into the next guess.
- The process repeats.
The macro stops when the absolute difference between the old and new interest values is less than the tolerance. A tolerance of 0.000001 is precise for this small example. A larger model may use a tolerance such as 0.01, meaning less than one cent of change.
Strengths and weaknesses
A macro can work when the model contains formulas that are difficult to solve algebraically. It also avoids enabling workbook-wide iterative calculation, which can hide unrelated circular references.
However, the result depends on running the macro. If a user changes an input and does not run it again, the displayed interest is stale. Macros may also be blocked by security settings, and some reporting environments do not allow macro-enabled files.
Keep a visible status cell such as Last solved at or Solution status. This makes it clear whether the schedule reflects the latest inputs.
> callout note > Store the converged result as a value, but keep a separate check that recalculates interest from the final debt balance. The check should show zero, or a very small rounding difference.
When to use this method
Use a copy-paste macro when:
- The model has genuine circularity.
- Opening-balance interest is too approximate.
- The circular formulas include complex limits or waterfalls.
- You can control workbook permissions and macro execution.
- Users understand that input changes require a new solve.
Prefer opening-balance interest for simple, transparent models. Prefer algebra when the circular relationship is simple enough to solve exactly. Use spreadsheet iterative calculation when users need formulas to update automatically and the workbook has strong circularity controls.
Exercise
Why does the macro write the calculated interest into a value cell instead of placing the average-balance interest formula directly in the interest cell?
Show answer
Writing the result as a value prevents a worksheet circular reference. The macro performs the iterations itself, then leaves the converged result in the interest cell.