Skip to content

Copy-paste macros in financial models

How to build a copy-paste macro that breaks a circular reference, with named ranges, a delta check and the settings that make it run fast and stop safely.

Tutorial · 6 minute read · Updated 2 November 2026

Copy-paste macro example workbook

The macro sheet, named ranges and VBA code from this tutorial, ready to open and adapt to your own model. Excel binary workbook (.xlsb).

VBA is best avoided in project finance models where possible. Some project finance calculations are inherently circular, though, and need VBA to copy and paste values to break the circularity. This tutorial covers the best practice approach to building copy-paste macros and the optimisations that make them reliable and efficient.

Why financial models need copy-paste macros

A circularity means the value of a cell depends on itself, so Excel cannot calculate it properly. The typical project finance example is debt sizing on a DSCR-sculpted repayment. The debt limit is the total principal repayable over the loan tenor given the project’s cash flow (CFADS ÷ DSCR, less interest). But the interest depends on the debt limit, because the limit sets how much debt is drawn at the start. That creates a circularity.

This tutorial covers that type of copy-paste macro, alongside a copy-paste macro for a debt service reserve account (DSRA) target balance.

Learn this in a room

Best Practice Project Finance Modelling

Build and sensitise robust cashflow models from scratch, faster in Excel. Hands-on, practitioner-led, in person or online. See dates and book your place.

Setting up the macro sheet, named ranges and delta check

Macro sheet

Set up every copy-paste macro on a dedicated “Macro” sheet. This makes the model more transparent and lowers the risk of pasting values into the wrong cells without noticing. Format the paste areas with a distinct cell style, labelled something like “macro paste”, so users know they are not input cells.

A dedicated Macro sheet in Excel showing the basic setup for two copy-paste macros, with orange-formatted macro paste cells clearly distinguished from input cells
Figure 1: The basic setup for two copy-paste macros on a dedicated Macro sheet.

Named ranges

VBA code should never reference specific cell addresses. Set up the copy and paste ranges for each macro as named ranges, so the code does not break when rows or columns are inserted or removed later. Set up named ranges in the Name Manager (Ctrl+F3).

Excel's Name Manager dialog box, showing named ranges set up for the copy and paste areas used by a VBA macro
Figure 2: Named ranges in the Name Manager.

Delta check

A check confirms whether the pasted value is within a set tolerance of the calculated value, so VBA can loop the copy-paste until it converges. For a time-series macro, run the check in each period, with an overall check that sums the absolute value of each period’s check and is used as the loop condition. Make each delta cell a named range too, so the macro can reference it dynamically.

Copy-paste macro code

The VBA code to copy and paste values is simple. The example below copies the values in the named range “Funding_Copy” to the named range “Funding_Paste”.

VBA code copying values from the named range Funding_Copy to the named range Funding_Paste using PasteSpecial with values only
Figure 3: Copying values from one named range to another.

Adapt the code for other named ranges by changing the names in quotes. The copy and paste ranges must be exactly the same size, in rows and in columns.

Looping until the delta check converges

To build the loop, VBA’s Do Until loop sets the condition that must be met before the code stops. For the debt limit macro described above, it could be set up like this.

VBA Do Until loop code that repeats the copy-paste operation until the delta check falls within the set tolerance
Figure 4: A Do Until loop, driven by the delta check.

Making the macro faster and safer

Manual calculation mode

During the macro, Excel recalculates after every copy-paste, which is not always needed and can slow the macro considerably. Set the calculation mode to manual at the start, recalculate after each copy-paste with Application.Calculate and restore the original setting at the end.

VBA code setting Excel's calculation mode to manual, xlCalculationManual
Figure 5: Setting the calculation mode to manual.
VBA code setting Excel's calculation mode to automatic except for data tables
Figure 6: Automatic calculation, except for data tables.
VBA code setting Excel's calculation mode to fully automatic, xlCalculationAutomatic
Figure 7: Fully automatic calculation.

The full code at the end of this tutorial shows how to detect the calculation mode when the macro starts, switch to manual while it runs and restore the original setting when it finishes.

Maximum iterations

Sometimes the loop never reaches a solution and keeps running. If that is a risk in your macro, add an iteration counter and a maximum: declare an integer variable set to zero, add one on each loop and add a condition that it must stay at or below a maximum, itself a named range in the model.

VBA loop code with an added iteration counter and a maximum iterations condition, so the loop cannot run indefinitely
Figure 8: A maximum iteration counter added to the loop.

Screen updating

Excel can turn off screen updating while a macro runs. Typically more than half of Excel’s processing during a copy-paste macro goes into updating the screen, so turning it off can more than halve the run time.

VBA code turning Application.ScreenUpdating off and on around a copy-paste macro
Figure 9: Turning screen updating off and on.

Status bar

With screen updating on, the Excel window flickers while a macro runs. With it off, the window appears to freeze. Updating the status bar during the macro gives the user a sense of progress instead, for example by showing how many loops have run.

Excel's status bar, at the bottom left of the application window, displaying a custom progress message while a VBA macro runs
Figure 10: The Excel status bar, showing macro progress.

Add a line to the copy-paste loop that sets the Application.StatusBar property.

VBA code updating Application.StatusBar with the current loop count inside the copy-paste loop
Figure 11: Updating the status bar from within the loop.

The full VBA code, with comments

The code below brings together every optimisation above, with a comment on each line. Commenting VBA as a matter of course makes it much easier to understand, update and reuse.

The complete, commented VBA code for a copy-paste macro, combining manual calculation mode, an iteration counter, screen updating and status bar progress updates
Figure 12: The complete, commented VBA code.

Copy-paste macro questions

Why do copy-paste macros exist in financial models?

They break circular references that Excel cannot resolve iteratively in a stable or auditable way. The most common case is a debt sizing calculation that depends on interest, which itself depends on the debt limit being sized.

Why use named ranges instead of cell references in VBA?

Cell references break without warning when rows or columns are inserted or removed, because VBA cannot tell the data has moved. Named ranges move with the model, so the macro keeps working as the model changes.

Why turn off screen updating during a macro?

More than half of Excel’s processing during a copy-paste macro is typically spent redrawing the screen. Turning screen updating off while the macro runs can more than halve the run time, though the screen looks frozen until it finishes.

What stops a copy-paste loop running forever?

A maximum iteration counter. Without one, a loop that never converges within its tolerance runs indefinitely. A counter and a maximum held in a named range make the macro exit safely even if it never reaches a solution.

Learn financial modelling in a room

Hands-on courses in person and online, taught to more than 20,000 people on one modelling standard.

Best Practice Project Finance Modelling

Build and sensitise robust cashflow models from scratch, faster in Excel. Hands-on, practitioner-led, in person or online. See dates and book your place.

View full course details: Best Practice Project Finance Modelling

Advanced Project Finance Modelling

Debt sizing, covenant monitoring, DSRAs and integrated three-way statements. Hands-on, practitioner-led training, in person or online. See dates and book.

View full course details: Advanced Project Finance Modelling

Financial Model Review

Error classes, testing technique and where AI-assisted financial model review earns its place. 1-day course from our award-winning Model Audit team.

View full course details: Financial Model Review

Browse all training courses

More on this topic

Tutorials

Using a Goal Seek macro to find the maximum debt limit

Size the maximum debt a CFADS profile supports at a target DSCR with Goal Seek, then automate the search with a short macro and a button.

Circular interest on average balances

Solve interest on an average balance with simple algebra instead of a copy-paste macro, so the circular reference never enters the model at all.

Services

Financial Model Development

Transaction and operational models built for you, lender-ready and documented, then handed over with the logic explained to your own team.

Financial Modelling Support

Modelling capacity when you need it, from a single rebuild to refinancings, operational updates and bespoke analysis on the models you run.

Learn to build these models yourself

We run public and in-house courses across the full financial modelling curriculum.