CHAPTER 8
Tools for Financial Modelling

In this chapter, we'll look at the basic, commonly used tools of hiding and grouping. We'll then cover some more advanced tools such as array formulas, goal seeking, PivotTables, and macros. Whilst the best financial models are the simplest and easiest to understand (and therefore often don't contain these complex tools), it's important that the financial modeller has a grasp on how to use these tools if functionality requires.

HIDING SECTIONS OF A MODEL

Being able to hide sections of a model is a very handy tool, especially when tidying up a model to conceal cells that are necessary for the model to work, but not necessary for the user to see. You can hide rows or columns in the model, or you can hide an entire sheet. If you have information in a model you don't want users to see (for example, unnecessary detail or a calculation that will only serve to distract from the model), you can hide the section of the model that contains the data.

Columns and Rows

It is possible to hide a column or row of data to stop it printing out, or to stop other people from viewing it.

You can hide multiple columns or rows at the same time. Just select all the columns or rows at the same time and follow the steps outlined above.

Sheets

Hiding sheets is also very useful. If you have information on a model you do not want users to see at all (e.g., salary information on budget models), you can hide the sheet with sensitive information, and then protect the workbook. The hidden sheets disappear from view, but links are retained as the sheet has not been deleted from the workbook.

Using Protection    As just outlined, there are two methods of hiding: either hide rows and columns or hide the worksheet itself. Depending on what is hidden, you might want to use another layer of protection to ensure that the data cannot be viewed. Password protection is a good option in such a case.

See the section “Bulletproofing Your Model” in Chapter 7 for greater detail on how to apply protection to models.

Errors Caused by Hiding

Hidden sheets, rows, and columns may hide complexity from the user and make the model less confusing, but many users don't like using what they perceive to be a black box. It's up to you, the model developer, to decide how much power you will give to model users. If you hide everything and then protect the model so that they can't see how it has been calculated, this makes the model easy to use, but it does not inspire confidence in users. It often depends on who is using the model. If a model is for other modellers to use, they probably won't appreciate being locked out of certain sections of the model, as they'd like to check it for themselves to ensure that it is working properly. If users have limited Excel use, then hiding with protection is appropriate to make sure they don't mess up the formulas or make unauthorised changes.

There are many well-documented cases where hidden rows and columns have been overlooked in financial models and caused significant errors. Barclays Capital was forced to file a legal relief motion relating to its acquisition of Lehman Brothers' US assets after a reformatting error in an Excel spreadsheet resulted in 179 toxic deals being mistakenly included in the purchase agreement.

The spreadsheet contained nearly 1,000 rows with more than 24,000 individual cells and had to be reformatted and converted into a PDF document before being posted on the bankruptcy court's website by the end of the day. A junior associate reformatting the work was unaware that the original Excel document included hidden rows containing contracts that were marked with an n to signify they should not be part of the deal. The document was posted on the website, but the hidden cells had become visible when the employee globally resized the rows in the spreadsheet—without the original n designations. The error was not spotted until Barclays posted a revised list of contracts, with notice to the affected parties.

This story illustrates why it is highly recommended to use the Grouping Tool when hiding rows and columns in financial models. Google “Excel Horror Stories” and you'll find a long list of the latest horrific Excel error stories. For more tips on how to avoid being part of your own Excel horror story, see the section “Error Avoidance Strategies” in Chapter 4.

GROUPING

Determining whether there are hidden rows or columns on your worksheet can be difficult. Using the grouping tool can make hidden data more obvious and avoid its being overlooked.

Go to the Data tab and select Group/Ungroup from the Outline section. When grouping is applied to a model, it will look like Figure 8.5 when collapsed. You can find this example, along with the accompanying models to the rest of the screenshots in this book, at www.plumsolutions.com.au/book.

Snipped image of a spreadsheet displaying a 2-column table with collapsed grouping.

FIGURE 8.5 Collapsed Grouping

The same sheet will look like Figure 8.6 when expanded.

Snipped image of a spreadsheet displaying a table for Telecommunications Product Projected Profitability with expanded grouping.

FIGURE 8.6 Expanded Grouping

Notice the little 1 and 2 numbers in the top left-hand corner for the rows and the columns. Clicking on these numbers is a very quick and easy way to expand and contract hidden rows and columns. Clicking 1 will contract the data, and 2 will expand it. One consideration when using the grouping tool is that it does make the viewing screen smaller, which might be a problem if space is an issue.

ARRAY FORMULAS

Array formulas are an advanced type of Excel calculation. Before we launch into what an array formula is, let me begin by saying that I don't recommend you deliberately include array formulas in your models unless there is no other practical way to achieve the same result. Array formulas can be difficult to understand, especially in older versions of Excel, and hard to edit if you don't know what they are, because you cannot change part of an array. In general, array formulas are very difficult to edit and audit because they add a new layer of complexity that is sometimes unnecessary. Most array formulas I have seen are legacy models built in older versions of Excel or Lotus, long before some of the more efficient functions became available. Other array formulas have been built by consultants who want to ensure that the client is unable to edit the model themselves, so guaranteeing themselves work in the future!

An array is basically just a collection of data of the same type that can be treated as a single entity. These types of formulas treat the entire array as a single input to the formula. The reason that array formulas are difficult to understand is that they don't follow the usual rules of ordinary formulas and if you have never seen an array formula before, they can be difficult to work out. Trace Precedents and Trace Dependents will work on arrays, but don't help very much. Therefore, if you are building a model for others to use, using array formulas is best avoided where possible, because they may have difficulty making the necessary changes to the model.

However, in order to seriously consider yourself an Excel super user, you should know how to build an array formula—or at least be able to recognise and edit one if you come across it—if only to remove it from the model and replace it with a far more auditable and user-friendly formula.

Array formulas are very powerful tools, and there are many reasons why modellers use them. One of the main advantages is security—nobody can accidentally delete part of the array block when using an array formula. Also, because the data can be manipulated as a whole block and used in the formula as a single unit, it's a lot harder to make a mistake when building the formula.

You can identify an array formula because, in Excel 2016 or earlier, it includes curly brackets (like these: {}). Note that Dynamic Arrays have been introduced to Excel 2019/365, which means that the curly brackets are no longer necessary. You can identify an array formula by the spill area, which shows as a fine blue line appearing as a border around the range when it is selected, as shown in Figure 8.8 below.

Data tables are a type of array formula—probably one of the most useful ones—especially for the financial modeller. (See “Using Data Tables for Sensitivity Analysis” in Chapter 11 for how to build a data table.)

Advantages and Disadvantages of Using Array Formulas

The advantages of using array formulas are as follows:

  • They ensure consistency, because all formulas in the table are exactly the same.
  • A model containing arrays will use less memory and be more efficient.
  • Because it's not possible to change a single cell on its own within an array formula, it is unlikely that you or someone else will change your formula accidentally.
  • Because array formulas are difficult to understand, it means that those with only basic Excel knowledge are less likely to change (and mess up) your formulas.
  • Array formulas do make it possible to perform some calculations that would otherwise be impossible. This is really the only reason you should use an array formula.

The disadvantages of using array formulas are as follows:

  • Although array formulas use less memory, if you use too many large arrays in one model it can slow down your calculations.
  • You cannot use column references (such as A:A or D:D) in your array formulas. This is not best practice in financial modelling anyway, so no great loss!
  • They are difficult to audit for many Excel users and require specialist skills, although this can be considered both an advantage and a disadvantage.

Simple Array Formula Example

  1. Create two simple blocks of data (arrays), as shown in Figure 8.7.
    Snipped image of a spreadsheet displaying a 3-column table with selected cells “=A2:A10*B2:B10” indicated in the formula bar.

    FIGURE 8.7 Entering an Array Formula

  2. Now, instead of simply multiplying Quantity by Price, we are going to create an array formula instead. Highlight the block of cells C1:C10 and type/select images in the formula bar, as shown in Figure 8.7.
  3. Now, if you are using Excel 2016 or earlier, hold down the Control and Shift keys while hitting Enter at the same time (Control+Shift+Enter). Excel 2019 users can simply hit Enter.
  4. The formula will appear in the whole array block, as shown in Figure 8.8.
    Snipped image of a spreadsheet displaying a 3-column table with a selected cell (C2). “=A2:A10*B2:B10” is indicated in the formula bar.

    FIGURE 8.8 Completed Array Formula

Try deleting one of the lower cells in column C. Note that with the exception of cell C2, you now cannot make any changes to the array block by changing an individual cell.

Please also note that array formulas were sometimes referred to as CSE formulas in Excel 2016 or earlier, because you had to press Control+Shift+Enter to enter them.

Array Formula Uses

Financial modellers generally resort to the use of array formulas only when it is not possible to do something any other way. There are many such instances, but some examples of these situations are as follows:

  • Data tables are a form of array formula that is extremely useful for scenarios and sensitivity analysis in financial modelling. Instead of changing inputs one at a time, an array shows hypothetically what an outcome would be simultaneously in a single table.
  • TRANSPOSE allows you to transpose a range of data, either vertically or horizontally, and retain links. We'll take a look at how to use this very handy technique in a moment.
  • Using a SUM and a VLOOKUP together as an array formula makes a very concise formula. For example, images will give you a sum of values in rows 2, 3, and 4 instead of having to do images Note that if you are using Excel 2016 or earlier, you need to hold down Control, Shift, and Enter for the array version of this formula to work.

Transposing Data Using an Array

One of my favourite uses of an array formula is to create a TRANSPOSE function, which will transpose data, allowing a link to be maintained within the model.

Let's say you have some city and temperature data in a table, as shown in Figure 8.9, but you'd like to transpose the data so that months and cities are switched around, as shown in Figure 8.10. You can create this sheet yourself, or a template can be found along with the accompanying models to the rest of the screenshots in this book at www.plumsolutions.com.au/book.

Snipped image of a spreadsheet displaying a table for Average Temperature Degrees Celsius with columns for Cities, January, February, March, April, May, June, July, August, September, October, and December.

FIGURE 8.9 Temperature Data

Snipped image of a spreadsheet displaying a table for Transposed Temperature Data with columns for months, London, New York, Sydney, and Moscow (left–right).

FIGURE 8.10 Transposed Temperature Data

Before you start cutting and pasting, try the transpose values tool first:

  1. Highlight the original table, and copy it to the clipboard using Control+C.
  2. Right-click in the cell that you want the data to appear, and select Paste Special.
  3. Check the Transpose box as shown in Figure 8.11, and click OK.
Paste Special Dialog Box displaying selected option buttons for All under Paste pane and None under Operation pane and a selected check box for transpose (enclosed by a rectangle).

FIGURE 8.11 Paste Special Dialog Box

This will paste all the transposed values as hardcoded data in a new table. Using this method creates two separate, independent tables of data.

Using a TRANSPOSE Array Function    You may wish to maintain the original table as the source data and have the second table linked to the first. Instead of linking each cell individually (which is time-consuming and prone to error), you could use a TRANSPOSE Array Function instead.

If you are using Excel 2019/365, select cell A9, type the formula =TRANSPOSE(A2:M6), and press Enter to create a transposed version of this table in range A9:E21. Note that if there is any cell already in the range blocking the spill area, the error #SPILL! will appear. Remove the obstructing cell and the array area will automatically respill.

For users of Excel 2016 or earlier, follow these five steps:

  1. Highlight a range with exactly the correct rows and columns for the destination data.
  2. In the formula bar, type the formula =TRANSPOSE, referencing the original data (i.e., images, as shown in Figure 8.12.
    Snipped image of a spreadsheet displaying 2 tables for Average Temperature Degrees Celsius with selected cells. “TRANSPOSE(B3:M6)” is indicated in the formula bar.

    FIGURE 8.12 Creating a TRANSPOSE Array Formula

  3. Now, hold down the Control and Shift keys while hitting Enter at the same time (Control+Shift+Enter).
  4. The formula will appear in the whole array block. Note that the curly brackets will appear around the formula: images. Remember that Control+Shift+Enter is not required for Excel 2019/365, there is no need to select the destination cells first, and the curly brackets will not show.
  5. Note that changes you make in the original block of data will be reflected in the second block.

GOAL SEEKING

Goal seek is a very handy and commonly used tool in financial modelling and analysis. Goal seek is used to adjust the value in a specified cell until a formula dependent on that cell reaches the result you specify. In other words, it will change the inputs such that the output is set to the exact amount you want it to be.

In order to run a goal seek, you must have:

  • A formula.
  • A hardcoded cell that drives that formula.

The formula and its input cell do not need to be on the same sheet or even in the same model. As long as there is a direct link between the two (no matter how many calculations are in between), the goal seek will work. However, it's important to remember that the input cell must be hardcoded. An input cell that contains a formula will not work.

A common use of goal seek is in break-even analysis. We normally want to know how many units we need to produce to break even (i.e., how many units we need to produce in order to recover our costs). In this instance, we'd change the number of units in the model until the profit amount is set to zero. See “Break-Even Analysis” in Chapter 9 for an example of this.

Here's another example in 10 steps. Let's say you borrow $1 million at an interest rate of 6.5 percent:

  1. Use the PMT function to calculate the monthly repayments over 15 years.
  2. If you use the PMT Insert Function dialog box, your input should look as shown in Figure 8.13.
    Snipped image of a spreadsheet displaying Function Arguments dialog box with Rate field labeled B2/12, Nper field labeled B3*12, Pv field labeled 81, and empty fields for Fv and Type.

    FIGURE 8.13 Loan Repayment Calculation Using PMT Function

  3. The result will be images. Put a minus sign in front of it to make it a positive number.
  4. Your formula should be images.

    See “Loan Calculations” in Chapter 6 for greater detail on how to use PMT and other loan calculation functions.

    Let's say that we can afford for our repayments to go up to, say, $10,000 per month. How much of an increase in interest payments can we afford? Maybe we should fix our rate.

  5. On the Data tab, in the Data Tools group, click on What-if Analysis and select Goal Seek from the drop-down list.
  6. In the Set Cell box, enter the reference for the cell containing the formula that produces the desired end result (images, in this case) as shown in Figure 8.14.
    Goal Seek dialog box displaying Set cell field labeled B4, To value field labeled 10000, and By changing cell field labeled $B$2. OK (selected) and Cancel buttons are at the bottom.

    FIGURE 8.14 Goal Seek Dialog Box

  7. In the To Value box, enter the result you would like to achieve in the Set Cell (type in images).
  8. In the By Changing Cell, enter the reference for the cell that Excel is to change (images, the interest rate).
  9. This will bring up the Goal Seek Status dialog box containing the result of your seek.
  10. Click OK to accept the new values, or Cancel to go back to the original values.

The answer to this problem is that we can afford for interest rates to increase to 8.75 percent. If the bank were to offer us a fixed interest rate of 8 percent, then we should take it!

Whilst this calculation could have been done by trial and error, it's much quicker to use a goal seek. Goal seek will work in huge models and run through a large number of calculations, giving the result you need to achieve your desired outcome.

STRUCTURED REFERENCE TABLES

The Table feature in Excel (not to be confused with PivotTables or Data Tables) is a great tool for organising and analysing large amounts of data. For this reason, like PivotTables, they are not used much in pure financial modelling, but as a very useful tool in reporting and analysis, they are also worth a brief mention.

The two useful features of a Table are:

  1. A Table will automatically resize depending on the number of rows. If you have a formula or a PivotTable referencing the Table, additional data will automatically be included in the range.
  2. Formulas created within a Table are automatically populated, hence ensuring consistency in formulas for blocks of data—a fundamental point of financial modelling best practice.

Also note that once you start using some of the Modern Excel tools for analysis or reporting, your data must be structured into a Table in order to feed into Power Query, Power Pivot, or Power BI, so that's another reason to get familiar with them.

If you want your data to stop being a Table and revert to being an ordinary block of data, click on the Table, and on the Design tab; under the Tools section, click on Convert to Range.

PIVOTTABLES

Excel PivotTables are another very useful and powerful feature of Excel to very quickly summarise, analyse, explore, and present your data. Figure 8.16 shows an example of a PivotTable that has been used to summarise the spend by location and product.

Snipped image of a spreadsheet displaying two tables (left) and PivotTable Fields pane (right).

FIGURE 8.16 Source Data and PivotTable

Using PivotTables in Financial Models

Useful as they are, PivotTables are not used very widely in building pure financial models. They are a very popular tool, however, and so it's difficult to be good at using Excel for business and financial modelling (which is the title of this book) without knowing how and in what context to use PivotTables. For this reason, I have provided a brief overview of PivotTables in this chapter.

The reason I don't recommend the use of PivotTables in pure, dynamic financial models is that they are static until refreshed, and this does not fit very well with the methodology of most financial models. As discussed in earlier chapters, the whole point of financial modelling is that you are able to change the inputs, and the outputs change! It's far too easy for a user to change the inputs, and then forget to refresh the PivotTable. This results in using incorrect outputs from the model.

As an alternative, I recommend the use of an alternative live, dynamic formula, such as SUMIF or SUMIFS, in place of a PivotTable when building a classic financial model that depends on inputs being changed. See “Aggregation Functions” in Chapter 6 for how to use the SUMIF and SUMIFS functions.

Whilst it is possible to change the settings so that the PivotTable will automatically refresh whenever the file is opened, there is no guarantee that the user will open and close the file before using the data, and it cannot be relied upon. It's not a bad idea to change the settings to automatically refresh in any case, however. You can do this by right-clicking on a PivotTable, then go to PivotTable Options as shown in Figure 8.17. On the Data tab, select “Refresh data when opening the file”.

PivotTable Options Dialog Box with selected Data tab displaying an encircled selected check box for Refresh data when opening the file. OK and Cancel buttons are at the bottom right corner.

FIGURE 8.17 PivotTable Options Dialog Box

Common Uses of PivotTables    PivotTables are widely used in data analysis, management reporting, and building dashboards. Here are some commonly used examples of PivotTables:

  • Summarising data, such as finding the average sales for each region and for each product, from a product sales data table.
  • Listing unique values in any column of a table (this can also be done with the remove duplicates functionality).
  • Filtering, sorting, and drilling down data in the reports without writing any formulas or macros.
  • Transposing data (i.e., moving rows to columns or columns to rows).

Other Things You Should Know About PivotTables

  • You can apply any formatting to the PivotTables. Excel has some very good PivotTable formats that can be easily accessed via the Styles on the Design tab.
  • You can easily change the PivotTable summary formulas. Right-click on the PivotTable and select the Summarise Data By option from Sum to Count or Average, for example.
  • You can also apply conditional formatting to PivotTables, although you may want to be a bit careful as PivotTables scale in size depending on the data.
  • Whenever the original data from which PivotTables are constructed changes, just right-click on the PivotTable and select Refresh Data.
  • Recommended PivotTables, as shown in Figure 8.18, is useful as it gives you a preview of what your data will look like in a PivotTable.
Snipped image of a spreadsheet displaying a table with all filled cells being selected. At the right is Recommended PivotTables dialog box displaying Sum of Price by Product pane.

FIGURE 8.18 Recommended PivotTables

Building a PivotTable

If you need to create a report summarising sales by customer, for example, you can follow these eight instructions:

  1. Highlight the entire database, ensuring that the headings are at the top of the range, or just click somewhere in the block of data.
  2. Select PivotTable from the Insert tab, in the Tables section. See Figure 8.19.
    Snipped image of a spreadsheet displaying a table with all filled cells being selected. At the right Create PivotTable dialog box with selected check boxes for Select a table of range and New Worksheet.

    FIGURE 8.19 Creating a PivotTable

  3. By default, it will put your PivotTable on a new page. If you prefer, you can change the options to locate it on the existing or a different page.
  4. Press OK. The PivotTable Field List will appear on the right-hand side.
  5. If you drag Customers into the Row Labels field and Price into the Values field, it will summarise your data and create a PivotTable report that looks like Figure 8.20.
    Image described by caption.

    FIGURE 8.20 Completed PivotTable with Field List

  6. If you now drag the Product field to the Rows field below the Customers field, it will split your report into subcategories.
  7. Try slicing and dicing your data in different ways. Swap the customer and product fields, or try moving products from the Rows field to the Column field.
  8. The PivotTable can now be quickly formatted using the drop-down styles on the Design tab.

Note that in versions later than Excel 2016, PivotTables automatically group dates in the column or row fields, as shown in Figure 8.21. If you'd prefer to group the dates manually, follow these steps:

Snipped image of an excel spreadsheet displaying a box labeled 1987, with a right click menu with Group selected. On the left are row labels Accounts, Admin, Brokerage, Communications, etc.

FIGURE 8.21 Grouping the Dates in a PivotTable

  1. Click on the first date in the column field, as shown in Figure 8.21, and select Group.
  2. Choose Months, Quarters, Years, or however you'd like the dates to be aggregated. In the example shown in Figure 8.22, we have chosen to group by Months, so we can see a forecast of fees by month in this PivotTable.
    Snipped image of an excel spreadsheet with a pop out dialog box for Grouping. It has data entry fields for Starting at and Ending at labeled 24/02/1987 and 18/07/2016, respectively. A box below has Months selected.

    FIGURE 8.22 Grouping by Month

Filtering and Using Slicers

Using the data from the previous example, we could drag the Product field into the Filters field in order to filter the data by Product, as shown in Figure 8.23.

Screenshot of an Excel spreadsheet displaying a drop down tab labeled Product (All) under columns F and G, enclosed by a box. Boxed on the right is a drop down tab labeled Product under PivotTable Fields in Filters panel.

FIGURE 8.23 Filter in a PivotTable

This filter can be used to show DVDs only, CDs only, or a combination. Note, however, that if we select “Multiple Items” as we have done in Figure 8.24, it ceases to show which items have been selected, which is not very helpful from a reporting perspective. Using a slicer in this instance will make the report more user-friendly.

Snipped image displaying an Excel sheet with columns from F to H. A popped out dialog box has a search bar and a box containing checked boxes for DVD and CD. At the bottom is another checked box for “Select multiple….”

FIGURE 8.24 Selecting Multiple Items in a Filter

MACROS

Many aspiring modellers think that they need to be proficient in macro building in order to become serious financial modellers. Whilst it's not a bad idea to have a working knowledge of macros—and the language they are built in, Visual Basic for Applications (VBA)—it's certainly not critical for a financial modeller to become a super VBA programmer. As discussed in previous sections, the best sort of financial model uses the simplest tools and introducing macros to a financial model brings a whole new level of complexity. It's also useful to note that if you are using a macro to perform a repeated series of actions on a regular basis, you should consider using Power Query instead as that might be a simpler and more robust way of achieving the same result.

Before launching further into the pros and cons of including macros in your financial model, let's have a quick overview of what macros are and how to build them. VBA in Excel is a huge topic in itself, and one I'm not planning on going into too deeply here. Once you start writing macros, it's quite easy to get hooked, as you can do some truly amazing things in Excel, which will bring the functionality of your work to a whole new level. If you develop an interest in the subject, there are lots of books and training courses specifically focused on macros and VBA. Make sure that you buy a book or attend a course on VBA for Excel and its use in finance, as there is a lot of programming done in VBA that is not finance-related.

A macro is a collection of commands performed in a set order. A macro enables you to repeat operations that you would normally do by hand, but it is much faster and, when written correctly, much more reliable. Often, a macro will do in seconds what takes hours or days by hand. It can also perform tasks that are physically impossible manually. If you find you are performing the same commands or actions over and over again, in exactly the same sequence, you can create a macro to record all those actions for you. You can then assign the macro to a button and run it using a single click, or you can even assign the macro to a keyboard command.

Macro Settings

Before we begin creating macros, there are a few settings in Excel you'll need to change:

  • Showing the Developer tab in the ribbon is not strictly required to record and run macros, but it contains tools that make it easier to run and edit macros, as well as some handy control tools and buttons.
  • Changing the security settings is required, and you must change this setting if you want to run macros.

The default installation version of Excel does not have these settings. You will need to change these settings only once, and you will not need to do it again unless you reinstall Excel, or move to another machine.

Showing the Developer Tab in the Ribbon    Whilst it is possible to record a macro by clicking on the launch button in the bottom left-hand corner of your screen, as shown in Figure 8.27, the Developer tab contains other functions that are useful when developing macros and other tools, so it's best to install the Developer tab.

Screenshot of Book1-Excel with Home tab selected displaying sheet 1 with A1 highlighted. At the bottom left is an icon beside a label Ready, enclosed by an ellipse.

FIGURE 8.27 Macro Launch Button

If you do not see the Developer tab, click on File—Options—Customize Ribbon. Check the Developer box. Excel for Mac users go to Excel— Preferences—Ribbon & Toolbar and check the Developer box. For more detailed instructions on how to do this, read “Showing the Developer Tab in the Ribbon” under “Form Controls” in Chapter 7.

Setting Macro Security Levels    Macros perform various automated functions that run via executable code. While most macros are useful and harmless, some malicious macro viruses can destroy data or otherwise damage your machine. For this reason, many people decide to disable macros altogether or turn security up so that macros can be run only from documents written by trusted publishers. However, turning up the security may disable legitimate macros, so changing the security level is an individual decision. You may also want to change this setting before you open documents from different sources.

You will need to determine the level of security appropriate for the way that you work. If you only ever run macros that you have written yourself, then Low may be suitable. High will be difficult to work with, as it won't allow you to run macros at all! If you often run macros from a trusted location, you may choose to select the Enable All Macros option.

To change your macro security settings:

  1. Click on the File menu in the top left-hand corner of your screen.
  2. Scroll down to Options or Excel Options at the very bottom and select it.
  3. Select Trust Center and click on Trust Center Settings.
  4. Choose the desired level of security.
  5. Close the model down, and then reopen it.

In Excel for Mac:

  1. Click on the Excel menu at the top left-hand corner of your screen.
  2. Click Preferences.
  3. Click the Security button, and go to the Macro Security section.
  4. Choose the desired level of security.
  5. Close the model down, and then reopen it.

Recording and Running a Simple Macro    The best way to get started with macros is to record one.

This macro will save within the Excel file you used when recording the macro. This macro is available whenever you have the file open.

Practical Exercise    Let's try recording a macro that will be useful. Say you want to change the formatting of a cell from 150000 to $150,000—a very commonly performed task. (This macro will save you some time, as it's not possible to change this formatting with a single mouse click or keystroke.) Follow these 12 steps:

  1. Type 150000 into cell A1 on a blank worksheet.
  2. Begin recording, as shown above. Call the macro FormatCurrency. Assign a shortcut key (e.g., Ctrl+m), and click OK. See Figure 8.29.
    Record Macro dialog box displaying data entry fields for Macro name labeled FormatCurrency and for Store macro in labeled This Workbook. At the bottom right are OK and Cancel buttons.
    FIGURE 8.29 Naming the Recorded Macro
  3. Select cell A1 and change the formatting to $150,000. This can be done through the menu bar, or right-click “Format cells” and change the currency to the desired format.
  4. Stop recording.
  5. Now we can test to see if the macro worked. Go back to cell A1 and change the formatting to a percentage, for example.
  6. Run the macro as shown above. The formatting of cell A1 will revert to the formatting we specified in the macro. Now we can edit the macro and make changes within the VBA code as follows:
    1. Select the Macros icon from the View or Developer tab on the ribbon. The Macro dialog box contains a list of all the available macros.
    2. Select the macro that you want to edit and press Edit. This will take you into the VBA coding editor, where you can manually edit a macro.
    3. Change things such as sheet names or cell references, rather than re-recording the macro. You can even make the macro run more efficiently by removing the duplication of the .Select command.
    4. Change the code, and close down the editor.
  7. Try editing your macro. If you haven't been into the VBA editor before, it can seem a bit scary, but don't worry. You can always close down the editor to get back to your Excel model.
  8. The VBA editor screen should look something like Figure 8.30.
    Snipped image of a window displaying Project-VBAProject on the left panel and data entry field labeled (General) on the right panel, with labels Sub FormatCurrency (), FormatCurrency Macro, etc.

    FIGURE 8.30 Viewing the Recorded Macro in the VBA Editor

    The text in green font is purely descriptive. Any text preceded by an apostrophe (') will be ignored by the macro when running. You can delete or replace this with documentation of your own, describing what the macro does.

    Take a look at the code. It contains two steps: it selects cell A1, and formats it as we have specified. This means that every time we run this macro, it will select cell A1 and format it. If we remove the reference to cell A1, it will change the formatting of whatever cell is selected. This is much more useful!

  9. Remove the descriptive text and the first line of code. Your code should now be:
    equation
  10. Close down the VBA editor and return to your model.
  11. Type some random numbers anywhere in your model—even on a different page.
  12. Select the cells and run the macro by using the shortcut. These numbers should change to your desired format.

Creating Macro Buttons

You can assign a macro to almost any object or shape on your Excel worksheet, including shapes, buttons, and even combo box drop-downs. The most commonly used object is a rectangular-shaped button. There are two ways of creating these buttons, either as shapes or traditional form buttons.

Macros in Financial Modelling Case Studies

There are hundreds of situations where macros can save time and increase accuracy. They might not necessarily be built and saved within financial models, but they could be used in the collection of the data that goes into the model. Here is a small sample of a few of the most common problems in financial modelling that are solved by macros. You can download some of these example models from www.plumsolutions.com.au/book.

  • A company is doing a salary comparison between different countries and wants to know how much they would need to pay in Malaysian ringgit (MYR) so that their salary is the same as someone working in Singapore. If a worker in Malaysia earns the equivalent of 100,000 MYR after tax, how much would the company need to pay the worker before tax? The problem is that tax is calculated on pre-tax salary, so our formula gives us a circular reference. We can use a macro with a goal seek to repeatedly set the pre-tax salary to the amount entered by the user.
  • Fifty identical budget templates have been created, and you discover a formula needs to be changed. Instead of making the change 50 times, record a macro. It will be much quicker and far less prone to error.
  • A nonprofit organisation sets its pricing so that all costs are fully recovered to break even. The costs keep changing though, and the user is a senior account manager who doesn't know how to do a goal seek in Excel. The modeller creates a simple macro using a goal seek so that all the user needs to do is change the costs and press the button to find out how much the pricing needs to change under the new costing.
  • A dump of information containing several thousand rows is exported from a database into Excel every day. The data needs to be formatted and manipulated manually to be used in a daily takings report. Automating this with a macro (or with Power Query) can literally save hours of manual data manipulation.
  • A reporting model is built using a PivotTable, but when new data is entered, the user sometimes forgets to refresh the PivotTable. The modeller builds a button to refresh the PivotTable every time it's pressed.

Dangers and Pitfalls of Using Macros

Handy as they are, macros should always be used with caution. Quite often formulas or filtering will achieve the desired result, without the need for building a macro. Always try a formula or standard Excel solution before considering the inclusion of a macro in your model.

  • Unless ranges are defined properly using relative cell references, macros don't move their references the way that formulas do, and therefore named ranges are recommended when building macros. If any data has moved since the macro was written, the macro will refer to the wrong cell. A badly written macro can copy and paste over data, and you won't know what it has done!
  • Visual Basic is a complex programming language and a skill that many people don't have. Therefore, many people are not able to edit or follow what a macro is doing—especially if it hasn't been documented properly.
  • Macros are time-consuming to write, and often a much quicker and more transparent solution can be built just as easily with a plain formula.
  • Running macros requires security settings to be changed (as shown above), and if your model is used by other people, they may not realise they need to change their settings, causing the model to not work properly.
  • Macro-enabled files need to be saved in .xlsm file format. If they are accidentally saved as a .xlsx macro-free workbook, the macros will be removed from the file. If this happens, the macros have been deleted and you'll need to either rewrite the code or copy it back in from a backup copy!
  • Unless you will be maintaining the model yourself, most business Excel users have more than enough to do without also trying to learn how to program.
  • If you're the one running the macro each time the model needs to be updated, that's fine, but what will happen after you're gone? If the process stops working due to a macro problem, it can hold up monthly procedures significantly.

Basically, there are more things that can go wrong if a financial model contains macros. When it comes to building financial models, consider whether a VBA solution is absolutely necessary before including it in your model. When building a financial model, macros should not be used unless there is no other option to achieve the required result.

SUMMARY

The tools for financial modelling covered in this chapter range from the basic, such as hiding and grouping, to more complex tools such as macros and array formulas. As always, we try to make our models as simple as possible, and as complex as necessary. Therefore, if you can create a model using just basic functions and tools, by all means do so.

If, however, you find that your simple solution does not provide your model with the desired functionality, then you may consider including a more complex nested formula, or even possibly a macro. The best sort of financial models are those that are clearly laid out and use very simple and clearly defined tools—not because we don't know how to create complex models, but because they are easier to follow. So, in conclusion, it's very difficult to be a top-notch financial modeller without knowing all the complex tools and functionality in Excel, but that does not mean that you should use these tools in every model. On the contrary, complex tools should be used only when absolutely necessary.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.47.208