Sensitivity Analysis Using VBA
Sensitivity Analysis Using VBA
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.
● 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.
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.
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.
Follow these steps to insert the “Sens” tool in your own models:
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.
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
'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
i=i+1
Loop
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.
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.
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.
Hedieh