Feb 02, 2020

Macro’s – From Beginner to Intermediate

So you’ve gotten to the stage where you need a macro in your model. That’s great! Are you sure you need to use one though?  If you need to automate anything to prevent getting a circularity, then that’s absolutely understandable. Or if you trying to automate some other task, like a goal seek… totally understandable too.

Some of the simplest advice I can give around macro’s is – make sure you absolutely need them! Now, why do I say this?

Macro’s get a bad rap (not a bad wrap, by the way, that’s more like when Chilango’s had a salmonella scare). And that’s because they’re generally the opposite of what you and I value in best practice models… which is transparency and flexibility.

But if you absolutely must have a macro, here are some guidelines in doing a basic copy paste macro. And yes, it starts with recording a macro, this is a great way to understand how actions translate from Excel into VBA (and so that you can understand how they translate back from VBA into Excel!)

Record a macro

View >> Macros >> Record Macro

  • Select area to copy
  • Copy
  • Select area to paste
  • Paste special >> values

Result should look like this

Refine the macro

We can replace the “.select” in both cases directly with the instructions to copy or to paste special.

We can also remove the extraneous detail around the paste special to just leave the “PasteValues”. This looks like this:

This makes the macro run faster – and is more clear to the user.

Automate with a Loop

The next step is to create a For Loop.  We can also name the ranges of the J10:M10 to make the macro more robust.

Change to a Do Until Loop

Note; this is interchangeable with the “Do While” loop – however Do While syntax will be while the value is <> 0

Setup a Delta between the sum of the copied values and the sum of the pasted values. Name this Delta (see here “Macro_IntDelta”)

Speed up and refine with the Direct Copy

Instead of a “copy” and “paste” setup, we can more directly assign the properties of one range to another. The properties we’re assigning are values.

To do this, we need to assign the Paste Range to be equal to whatever the Copy Range is.

The below screenshot shows both Step 4 and Step 5.

So that’s pretty much it, in getting to an “intermediate” level of knowledge with macro’s. Is it truly intermediate? Well maybe not quite, because you may not have the feeling of what changes what in a macro… or how you can trouble shoot etc.

But these steps (especially the DO LOOP, and refining with DIRECT COPY are steps that a lot of even quite good financial modelers miss).

Good luck!

Get Debt Repayment Calculations

Fet the .xlsx model which shows the four different calculation types

Popular Tutorials

NOV  20TH  2019

Calculating Debt
Repayment

Whether you’re a company, a fund, or a project… it’s likely that you have to repay debt.

NOV  17TH  2019

Working Capital

Working capital seems to be an area of confusion in financial modeling and adjusting them so we get the cash item.

NOV  10TH  2019

De-risking Your Model

Whatever type of model you have in front of you – for Corporate Finance, Project...

FEATURED TRAINING

Learn the Secrets of the World’s Top Financial Modelers

Get the behind-the-scenes top 15 Excel tips and shortcuts I use to build financial models known only by top financial modelers

Get Started
Close

Learn the Secrets of the World’s Top Financial Modelers

Get the behind-the-scenes top 15 Excel tips and shortcuts I use to build financial models known only by top financial modelers