0% found this document useful (0 votes)
30 views

Sensitivity Analysis Using VBA

This manual teaches how to build a sensitivity analysis template in Excel using VBA. It provides steps to insert the sensitivity template and VBA code into a financial model. This allows running sensitivities by changing input scenarios automatically. The document outlines linking input and output cells to model calculations and assigning a macro to run the sensitivity analysis with one click.

Uploaded by

Garchomp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Sensitivity Analysis Using VBA

This manual teaches how to build a sensitivity analysis template in Excel using VBA. It provides steps to insert the sensitivity template and VBA code into a financial model. This allows running sensitivities by changing input scenarios automatically. The document outlines linking input and output cells to model calculations and assigning a macro to run the sensitivity analysis with one click.

Uploaded by

Garchomp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

This manual and accompanying workbook are designed to help you build a

sensitivity analysis into your models using VBA. The workbook is password free so
you have access to the VBA code and can review and edit the spreadsheet.

In this manual you will learn:

● how to insert the Sensitivity template and the related VBA code into your
own financial model
● how to enable another macro to run simultaneously while running the
sensitivities

It doesn’t cover the important step in conducting a sensitivity analysis which is how
to identify the outputs and inputs of the sensitivity analysis.

If you want to know more about how to identify your key performance indicators
and sensitivity parameters check “Season 2, Episode 8” of the Financial Model
Detective book.

Color codes used in this spreadsheet are listed below. Once you’ve transferred the
“Sens” sheet into your model, you might want to harmonize the color codes with
the color codes you have in your model.

Here are the steps to follow:

Step 1: Preliminaries
● Download and open the “Sensitivity template Using VBA” workbook
● Open the financial model where you want to insert the “Sens” sheet
● Make sure that your financial model is macro enabled.

Check if the file extension is either .xlsm or .xlsb

To save as macro enabled.


1. Click the File tab and then choose Save As. The Save As dialog box appears.
Or use shortcut F12 for windows/Command + Shift + S in Mac
2. Enter a name and select a location for your workbook.
3. Click the Save as Type drop-down arrow. A list of file types appears.
4. Select Excel Macro-Enabled Workbook.
5. Click Save.
● Display the Developer tab
If the Developer tab is not available, do the following to display it:

In Mac:
1. Select Excel > Preferences >
Ribbon & Toolbar.
2. Under Customize the Ribbon,
select Main Tabs and then
check Developer.
3. Click Save and then close
Excel Preferences.

In Windows:
1. On the File tab, go to Options >
Customize Ribbon.
2. Under Customize the Ribbon and
under Main Tabs, select the
Developer check box.

Step 2: Insert the Sensitivity template into your own model

Follow these steps to insert the “Sens” tool in your own models:

Once you have both files open:


1 2
go to “Sens” sheet in “Sensitivity right click on the sheet labeled
Template dataTable v01.xlsx” file “Sens” and click on Move or Copy and a
new window will open.

3 4
at the bottom of the window, select your filename in the To
check the Create a copy box to only Book drop down list.
copy and not move the sheet.

5
click ok and go back to your
financial model. You should now have
the same sheet sitting in your model.
Now if you go back to your financial model, you should find the “Sens” sheet in your
workbook.

Step 3: Insert the VBA code into your own model


Go to your financial model and open the VBA tab within your own financial model.
To do this :
Go to the Developer tab and click on the visual basic button or use shortcut Alt+F11
in Windown/fn + Option+F11 in Mac

Once in the VBA editor, at the top left


corner of the editor window, right-click
on your workbook name in the Project-
VBAProject pane and select
Insert/Module from the menu.

Copy and paste the below code (highlighted) into the new module that you just
created:
Sub automateSensitivityTable()

'Declare variables.
Dim i As Integer
'Dim InitialScenario As Integer
Dim ScenarioCount As Range
Dim rngScenarioCopy As Range
Dim rngScenarioPaste As Range

'Populate variables with data from sheet.


Set InitialScenario = Range("Scenario_Switch")

'Set range variables to anchor cells on the worksheet.


Set ScenarioCount = Range("Scenario_Count")
Set rngScenarioCopy = Range("Scenario_Copy")
Set rngScenarioPaste = Range("Scenario_Paste")

'Start the counter at 1


i=0

'Starting at an anchor point for each scenario number we test whether the cell is empty before continuing.
Do While ScenarioCount.Offset(1, 0).Errors.Item(1).Value = False

Set rngScenarioCopy = Range("Scenario_Copy")

'Paste output into column.


rngScenarioPaste.Offset(0, i).Value = rngScenarioCopy.Value

'Call another macro


'Call X

'Input scenario number into the scenario manager.


InitialScenario.Value = i + 2

i=i+1

Loop

'Return scenario back to original number.


InitialScenario.Value = 1

'Call and run another macro


'Call X

End Sub
NOTE: If you need to run another macro while doing sensitivities then you need to
do an adjustment in the yellow highlighted section of the code:
● come to the yellow highlighted section of the code
● Delete “X” and put the name of the macro that you want to run
simultaneously with the sensitivities
● Delete the apostrophe mark

Well done! you have the skeleton in your model, now you have to breath life into it
by making the links. Save your file by pressing Ctrl +S in Windows/ Command + S in
Mac to save the changes we’ve made.

Now we are completely diving into your territory, meaning in your own financial
model. we have to link the sensitivity parameters in the “Sens” sheet to your model.
Step 4: Define your customized inputs, output sensitivities and
scenarios

1 2
In your file, go to the newly In the top section, in cells D9:D18
created sheet “Sens” type down the list of sensitivity inputs
that you have defined in step 1.

3 4
In the next column in cells E9:F18 in cells G9:H18 type in your
define the sensitivity outputs. scenarios.
Step 5: Now you need to link the sensitivity parameters to your
model

For example, let's say that Capex is one of your sensitivity inputs. Go to your model
where you have the final capex line that feeds into your model and multiply the
capex figures by (1 + Sens!$E$24). Do the same thing for other sensitivity
parameters.

Step 4: Define the inputs to create your desired scenarios


modify cells F24 to O33 to reflect the scenarios that you have defined.
Step 6: Link sensitivity outputs in the “Sens” sheet to your model

link cells E40 to E49 to results that you


calculated somewhere in your model.
For example, if you want to see the total
project cost as one of your results, then
link cell E40 to where in your model
you have the total project cost
calculated. Do the same thing for the
other cells.

Step 7: Assign a macro to the macro button and run the


sensitivities

1 2
in the “Sens” sheet, eight click on in the new window on top in the
the pink arrow button and select Assign Macro name, select
Macro and then OK. automateSensitivityTable and select OK
3
Click on the button and wait for
the sensitivities to run.

And you're done!

Congratulations on successfully creating a sensitivity analysis using the template. I


hope you enjoyed the process and that you can use it from now on in your models.

Once you’ve had a chance to use the sensitivity template, I would love to hear from

you. please share your thoughts and ideas directly in the comments.

In the meantime, stay $locked$ and happy modelling.

Hedieh

You might also like