Many self-proclaimed financial modeling experts will tell you that you need to have a good grasp of Visual Basic for Applications (VBA) and macros. Well at Video Financial Modelling we are here to tell you that you don’t. Well not if you’ve read this article.
Why do we need macros?
In simplistic terms a macro is a program that implements a task. VBA macros are often used to automate tedious financial modeling tasks or to break circularities.
Why don’t you need to be a macro master?
Well there are a number of reasons why you don’t need to be a VBA macro master.
- Firstly, we’re going to give you some common macros that you can simply copy and paste into VBA in your financial model
- Secondly, it is really easy to record your own macros and then manipulate them to suit your particular situation. We’ll look at an example a bit later
- Thirdly and finally in all the financial models we have seen (and we’ve seen a lot) there are only a few situations that require a macro. We will run through each below.
Firstly let’s look at an example on how to record a macro.
Example – Manually recording a macro and then manipulating it
In this example we are going to look at Firstly open the accompanying blog workbook. Also remember you can watch the blog youtube video to follow this example. To start recording a macro, press View on the menu and then select Macros. Select Record Macro on the popdown menu. Let’s call the macro DebtSolve.
Select the Debt Amount – Calculated value and then copy the cell (CTRL+c) and paste special values (Home, Paste, Values) in the Debt Amount – Hardcoded cell. Press enter.
Now press the stop button in the bottom left hand corner.
Go to Data, Macro and push View Macro. Then select the DebtSolve macro and press edit. We are now going to put the named cells into the macro and add in a loop.
Ok, let’s firstly put the relevant named ranges in. Just copy both the DebtCalc and DebtHard and put them in place of the relevant cells in the VBA file.
Now let’s add the loop. Simply copy and paste the following code: Do While Range(“DebtCheck”) <> 0.
We’ll also have to put in: Range(“DebtCalc”) to replace the Selection before copy.
Place it at the start of the code after the Sub Debt Solve() and the green commentary. And now put a Loop before the End Sub. The final macro should look something like this.
This loop will keep copying and pasting the calculated debt amount into the hardcoded debt amount, until these values converge and the debt check becomes zero.
Now let’s go and select Insert on the menu, select Shape and then a rectangle. Draw it on the sheet. Then right click on the rectangle and select Assign Macro and press DebtSolve.
Now press the button you just created and voila you’ve created a macro that solves a common financial modeling circularity. Change the hardcoded value or the arrangement fee and press the button again. It should solve.
In the next part to this macro series we are going to look at the main types of macros you’re going to need when you’re financial modeling.