Tips & Tricks For Excel-Based Financial Modeling A Must For Engineers &
Tips & Tricks For Excel-Based Financial Modeling A Must For Engineers &
MIAN
Management Collection
ysts, John A. Doukas, Editor
ncepts
Excel™
TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING, VOLUME II
utilize
ire the
on it. It
e art of
Tips & Tricks
macros, for Excel-Based
Financial Modeling
y used,
nctions
is not
o show
tomate
A Must for Engineers &
se who
project/
Financial Analysts
e in the
Volume II
panies
working
g and
rojects.
for the
rojects,
plants,
project
vanced
M. A. Mian
ourses
subject
thor of
hanical
mineral
48-6
Tips & Tricks for
Excel-Based Financial
Modeling
Tips & Tricks for
Excel-Based Financial
Modeling
A Must for Engineers &
Financial Analysts
Volume II
M. A. Mian, PE
Tips & Tricks for Excel-Based Financial Modeling: A Must for Engineers &
Financial Analysts, Volume II
10 9 8 7 6 5 4 3 2 1
Keywords
advance Excel, Excel based financial modeling, financial modeling, invest-
ment evaluation, investment evaluation modeling, Microsoft ExcelTM,
project economics
Contents
Preface ..................................................................................................ix
1. Financial analysts.
2. Engineers involved in budgeting, AFE preparation and project eco-
nomics (engineering economics).
3. Personnel involved in preparation of corporate business plan.
4. New business development personnel.
5. Professionals related to investment, equity research, credit, project,
mergers and acquisition, and corporate finance.
6. Students pursuing financial and engineering education (undergradu-
ate and graduate) at the university level.
7. The in-depth knowledge of Excel will greatly enhance their efficiency
and out of the box thinking.
1. Enter the names of the three scenarios in Cells A3, A4, and A5 as
shown in Figure 1.1a.
Figure 1.3 Data Validation dialog box with a list in the Source
The same will apply to the Base Case Scenario and the High Case
Scenario. The crude oil is exported to Far East (FE), Europe (EU), Asia,
or the United State of America (USA). The price for each destination will
be different because of the transportation and supply and demand for a
particular product in the region.
Here we will show how to set up dropdown menus to enable us to
select a particular pricing scenario from the pricing worksheet.
Figure 1.4 shows various pricing options or scenarios available in the
“Pricing” worksheet. These will be located somewhere away from the
main body of the model, either to the right or at the bottom. In this list,
the product types in Columns B, C, and D are dependent on the Prod-
ucts in Column A. This means that if I pick Crude_Oil, I should be able
to select what quality of crude oil. Column E has the pricing scenarios.
The Low Case has (a) four pricing for the crude oil, (b) two prices for
condensate, and (c) four prices for the export products. The same are
repeated for Base Case and High Case scenarios.
Now we start selecting the options available to us. First, we select
the scenario (Low Case, Base Case, or High Case) in Cell B1. These are
common to all the product categories so they can be treated in the same
way as shown in the preceding section. Follow the following steps to get
a dropdown menu for the scenarios.
Figure 1.5 Selecting the Base Case pricing scenario from the scenario
dropdown menu
Next step is to select the product type in Cell B2. Follow the following
steps to get a dropdown menu for the product type. For this, we need to
define Range Names.
1. ProductCategory
2. CrudeOil
3. Condensate
4. ExportProducts
Figure 1.7 The defined Range Names in the Name Manager dialog box
2. Click on the Data Validation icon, the Data Validation dialog box, as
shown in Figure 1.8, appears.
3. Select List in the Validation criteria Allow dropdown.
Figure 1.8 Data Validation dialog box for the dropdown menu of
Product Category in Cell B2
8 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Now we add the third dropdown menu in Cell B3, the outcome of
this is dependent on what is selected in Cell B2. This requires the use of
Excel’s INDIRECT function. Follow the following steps:
Note: The items to appear in the first dropdown list must be one-
word entries, for example, Crude_Oil or CrudeOil and so on. In the next
section, we will deal with multiword entries. In addition, the names of the
dependent lists must be exactly the same as the matching entry in main
list. For example, the dependent list to be displayed when “Crude_Oil” is
selected from the first dropdown list should be named CrudeOil. It is also
recommended that the list in the dropdown menus is either in alphabeti-
cal order for easy reference or in some other logical order. Also remember
that characters such as the hyphen (-), ampersand (&), and so on, are not
accepted in Range Names.
CREATING DROPDOWN LISTS 9
Figure 1.11 Selecting the Crude Oil from the Product Type dropdown
menu
1. CrudeOilArabExtraLight
2. CrudeOilArabLight
3. CrudeOilArabMedium
4. CrudeOilArabHeavy
5. CondensateCondensate
6. CondensateKhuffCondensate
7. ExportProductsPropane
8. ExportProductsButane
9. ExportProductsPentanes
Repeat this step for all the other combinations. The final Name
Manager is shown in Figure 1.13.
Figure 1.13 Name Manager for the dropdown menus in Cells B2,
B3, and B4
Now we are ready to create the third dropdown menu in Cell B4. This
menu is dependent upon the selections in Cells B2 and B3. A new for-
mula is required for this step. If you notice, we have combined the items
in Cells B2 and B3 to create the name range. In the Data Validation,
they have to be split again by applying Excel’s INDIRECT and SUBSTI-
TUTE formula. This will split the name (concatenates) into two names
and remove the spaces from the names. For example, in Cell B4, the data
validation formula would be:
INDIRECT(SUBSTITUTE(B2&B3,” “,””))
where Cells B2 and B3 contain the first and second dropdowns, respec-
tively. The Data Validation dialog box with this formula is shown in
Figure 1.14. The completed dropdown menus are as shown in Figure 1.15.
12 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Figure 1.14 Data Validation dialog box for creating the dependent
dropdown in Cell B4; the dropdown in Cell B4 is dependent upon the
combined selections in Cells B2 and B3
4. Click on the Developer checkbox under the list of Main Tabs on the
right as shown in Figure 1.17.
5. Click on the OK button. This will add the Developer tab to the
Ribbon.
The FORM Controls are used to (a) easily reference and interact with
cell data without using VBA code, (b) add controls to chart sheets, and
(c) attach an existing macro to a control so a macro is executed when a
user clicks on the control.
14 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
1. Click on the desired button on the Forms toolbar, the mouse pointer
will turn into a plus sign.
CREATING DROPDOWN LISTS 15
Figure 1.18 The Form Controls dialog box under the INSERT tab of
the Developer tab
2. Click the worksheet location where you want the upper-left corner
of Form Control or ActiveX button to appear.
3. Drag the list box to where you want the lower-right corner of the list
box to be. If the button has to be in only one cell then just cover the
grid lines of the cell.
4. Right click on the button Click on Format Control. The Format
Control dialog box will appear where the desired formatting can be
done. The Format Control dialog box can also be accessed by click-
ing on Properties
you want the lower-right corner of the Button to be. Release the
left click, an Assign Macro dialog box will appear as shown in
Figure 1.19. Assign the macro now or click OK, the macro can
also be assigned later. In this example, the Button is shown in
Cells A1:B2 as shown in Figure 1.20.
Figure 1.19 The Assign Macro dialog box for the Button in
Figure 1.20
Figure 1.21 The Format Control dialog box for the Combo Box
18 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
d. Right click on the Check Box created. Format Control dialog box
will appear as shown in Figure 1.23. Click on the Control tab
and assign the cell link to $B$1.
Figure 1.23 The Form Control dialog box for Check Box
e. If more than one Check Box has to be created then copy the
Check Box just created and paste it in the other desired cells.
f. Once the Check Boxes are copied to the other cells, change the
cell link for each by repeating Step 3d.
g. Change Text—The title or reference of the Check Box can be
changed using: Right click on the Check Box Click on Edit
Text in the dropdown list.
h. The Check Boxes created are shown in Figure 1.24 with the result
in Cells B1:B4.
Figure 1.25 shows an example of how the Check Box option
can be used. In this example, we have revenue from three countries
and we need to look at the total and average revenue per country or
20 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Figure 1.26 The Spin Button (Form Control) Format Object dialog
box
Figure 1.28 Format Control dialog box for the List Box (Form
Control)
iii. Link the cell link to Cell B1 as shown in Figure 1.29. Cell B1
will show the sequence number of the selected option from
the List Box.
iv. By reducing the height of the List Box to cover Cells A1:A2
only will show three items out of the list in Cells C1:C4. The
up and down arrows will then become live to scroll the list
up and down.
24 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Figure 1.30 Format Control dialog box for the Option Button
CREATING DROPDOWN LISTS 25
iv. Link the cell link to Cell B1 as shown in Figure 1.31. Cell B1
will show the sequence number of the selected option from
the Option Button.
7. Group Box (Form Control)—If we are using more than one set of
Options Buttons or Check Box or some of the other Form Controls,
they will not work properly if they are not grouped separately in
different categories. Figure 1.32 shows one set of Option Buttons
for the product type and another set for the corresponding pricing
scenario. However, the worksheet does not differentiate between the
two unique sets. We can overcome this problem by enclosing each
unique set under a Group Box as shown in Figure 1.33. Once the
two sets are grouped then the cell link should be assigned to each
group.
Figure 1.32 Option Buttons for product type and pricing scenario
Figure 1.34 Format Object dialog box for the Scroll Bar Form Control
1. Data validation
2. Circle invalid data
3. Clear validation circles
The Input Message (Figure 2.3) in the Data Validation dialog box
prompts the user to a user-specified message explaining the kind of
data allowed in a cell. Figure 2.3 shows formatting of Cell A1 to accept
only text of minimum length 5 and maximum length 10. To create this
restriction, select Cell A1 Data Validation Allow Text Length
Minimum 5 Maximum 10 OK.
Now create an input message, which will show up when cursor is
placed in Cell A1. The message will not be shown if the cursor is placed in
any other cell. The error message should be clear and meaningful so that
anyone entering data into this cell knows what the message means. Enter
USING EXCEL’S DATA TAB 31
OK. The message is shown in Figure 2.3. Figure 2.4 shows the message
when cursor is placed in Cell A1.
Now create a message that will appear when incorrect data is entered.
Select the cell that need a rule and enter the Error Alert as shown in
Figure 2.5. Now try to enter any value (not text) in Cell A1. We tried
to enter 1 in Cell A1. As soon as 1 is entered in the cell the error mes-
sage, as shown in Figure 2.6, appears alerting the user to take corrective
action. Click on Retry or Cancel to correct the entry. In this example, we
specified the text length between 5 and 10. The Settings dialog box has
a dropdown list allowing the user to enter other specifications such exact
text length and so on.
32 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Fill feature to fill cells with data that follows a pattern or that is based on
data in other cells. In the latest versions of Excel another feature is added
which is called Flash Fill. The Flash Fill option of Excel helps in filling out
data based on an example. This feature starts working when it recognizes
a pattern in your data. The feature works best when there is some consis-
tency in the data you are going to enter.
You have to make sure that the Fill Flash is on. This is done by Click
File Options Advanced Automatically Flash Fill OK. The
activated Flash Fill is as shown in Figure 2.8.
(a) (b)
Figure 2.9 (a) Using Excel’s Flash Fill function (b) After use of
Flash Fill
data from another source, it is prudent to check for the duplicate data
error. You can specify columns or rows in which to remove the duplicates
or the duplicates can be removed from the entire dataset. The only con-
cern in automatically removing the duplicates, without actually seeing the
removed data, is that it does not allow you to do any analysis before the
duplicates are removed.
Figure 2.10 shows certain data and we can clearly see the dupli-
cate entries since it is a small list. We want to remove the duplicates
automatically.
Figure 2.13 Dataset of Figure 2.10 after the duplicate data removed
Besides using the Excel’s Remove Duplicates feature, you can also
clean the dataset by using (a) conditional formatting (highlighting the
cells that may have duplicates) applicable for small datasets, (b) pivot
table, (c) sorting the data, or (d) using advanced filters.
to see in routine analysis. The worksheet may look cluttered if all these
rows and columns are shown in the worksheet. For example, I have five
product streams with corresponding five product prices and five reve-
nue calculations. At the bottom of the revenue calculations, I have Gross
Revenue. In routine analysis, the only data that is worth seeing is the
Gross Revenue. Therefore, I can group and hide all the rows that perform
detailed calculations to arrive at the Gross Revenue.
Similarly, you may have several rows with monthly sales figures and
one row with the sum of all these sales figures. This could become clut-
tered if you are dealing with sales over several years, that is, 12 months/
year times 5 years will be 60 rows of sales data. We can group and hide
these 60 rows of data and only show the total for 7 years or year-by-year.
Note that at any time the analyst wants to look into the details, the data
could be temporarily ungrouped.
Figure 2.14 shows revenues for six products and the Gross Revenue of
all the six product streams. We need to only see the Gross Revenue so we
can group (hide) the revenue of the individual products.
Figure 2.15b The grouped revenue table showing only the Gross
Revenue
2. Ref1—The first named range or reference for which you want the
subtotal.
3. Ref2—Optional named ranges or references 2 to 254 for which you
want the subtotal.
Figure 2.18 Figure 2.16 after the SUBTOTAL functions are inserted
42 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Once the table is ready then you can select the details you want to see.
Clicking on Button 1 shows only the Grand Total, clicking on Button 2
will show the Subtotals and Grand Total as shown in Figure 2.19, and
clicking on Button 3 will show the entire table. Similarly, clicking on any
of the negative (–) signs in Figure 2.18 can be used to show the desired
details.
Figure 2.19 Collapsed table showing only the subtotals and grand total
The following steps are followed to consolidate the cash flows of Projects
1 and 2 together.
Lot of times there may be an existing template in which the user would
like to consolidate the data of the worksheets. Such a template is shown
in Figure 2.28.
1. Scenario Manager
2. Goal Seek
3. Data Table
A Goal Seek dialog box, shown in Figure 2.31, appears when clicking
on the Goal Seek function under the What-If Analysis tab.
The Set cell refers to the cell which contains the formula to perform
the desired calculation. To value is the answer to be obtained from the
formula cell. By changing cell has one of the variables of the formula in
the formula cell.
A typical problem that we can solve using the Goal Seek is to find
out how much money we can afford to borrow from a bank based on (a)
annual interest rate of 5 percent, (b) monthly payments over a payback
period of 10 years, and (c) maximum monthly payment of $2,000. The
data entry is shown in Figure 2.32. Cells B1 to B4 are inputs and Cell B5
has PMT(B4/B3,B2*B3, B1) formula to calculate the monthly pay-
ment. The objective here is to change the loan amount in Cell B1 until
we arrive at a monthly payment of $2,000 in Cell B5.
Figure 2.34 Cash flow for the calculation of breakeven price using
Goal Seek
52 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
The objective here is to find the gas price that will make the NPV
equal to zero (NPV=0). Place cursor in Cell B9 Data What-If
Analysis Goal Seek.
The Goal Seek dialog box appears as shown in Figure 2.35. Enter To
value: zero (0) and By changing cell: $B$3 and enter OK and OK again
on the Goal Seek Status dialog box. The price in Row 3 changes to $10.89
and the NPV =0.
Figure 2.35 Goal Seek dialog box for the problem in Figure 2.34
Figure 2.36 Using the Data Table function on the cash flow in
Figure 2.34
Figure 2.37 The Data Table dialog box with Row input cell for
Figure 2.36
Now let us repeat the sensitivity but this time using two variables
(OPEX and CAPEX) simultaneously. The following steps are followed
in performing dual variable sensitivity analysis using the DATA TABLE
function.
6. Enter C5 in the Column input cell in the Data Table dialog box
(shown in Figure 2.39) since the variable OPEX are in a Column.
Note: when using a string of the same variable, make sure that each
variable in the string is connected to the first variable (the Cell that
USING EXCEL’S DATA TAB 55
will be specified in the Data Table dialog box) in the string. It could
be just by = sign or some other formula/relationship such as showing
increasing or decreasing trend as applicable. In this example we equate
Cell D5=Cell C5, Cell E5=Cell D5, Cell F5=Cell E5 and so on.
7. Click on OK in the dialog box
8. The NPVs are generated in Cells C10:E14 as shown in Figure 2.40.
It can be seen that Cell D12 gives the same NPV as in Cell B9
because it is at the same OPEX ( $300) and CAPEX ($2,500), that
is, intersection of $2,500 and $300 in Cells B9:E14.
Figure 2.40 Using the Data Table function with sensitivity on two
variables
3. Click on Add in the Scenario Manager dialog box and fill it out as
applicable:
a. Scenario name: Low Case.
b. Changing Cells: C2, C5, and B6. These Cells are referring to
(a) the units sold, (b) OPEX, and (c) CAPEX, respectively.
c. Comment: Optional, any description can be added for reference
in the future.
USING EXCEL’S DATA TAB 57
4. Click on OK.
5. The Scenario Values dialog box, as shown in Figure 2.43, appears. In
the Low Case scenario we assume that the units sold will be reduced
by 10 percent, OPEX will increase by 10 percent, and CAPEX will
increase by 10 percent. So 90, 330, and 2,750 are added for the
Changing Cells C2, C5, and B6, respectively.
Figure 2.43 The Scenario Values dialog box for the Low Case scenario
58 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Figure 2.44 The Scenario Values dialog box for the Base Case scenario
Figure 2.45 The Scenario Values dialog box for the High Case scenario
8. The Scenario Manager dialog box appears again, this time displaying
the names of all three scenarios—Low Case, Base Case, and High
Case—in its Scenarios list box. The Scenario Manager dialog box,
incorporating the three scenarios, is shown in Figure 2.46. The result
(NPV in this case) for each scenario can be instantly observed by
clicking on the scenario in the Scenario Manager dialog box and
click on Show.
a. The Low Case will show NPV of $439.
USING EXCEL’S DATA TAB 59
b. The Base Case will show the same NPV as before, that is, $1,185.
c. The High Case will show NPC of $1,931.
9. The scenarios can be updated anytime by highlighting the scenario
in the Scenario Manager dialog box and click on Edit.
10. Excel will generate a summary by clicking on the Summary in the
Scenario Manager dialog box.
a. Click on Summary in the Scenario Manager Scenario Sum-
mary dialog box (as shown in Figure 2.47) appears.
b. Tick the desired Report Type, that is, Summary or Scenario Pivot
Table Report in the Scenario Summary dialog box.
c. Link the Result Cells to the NPV in Cell B9.
11. Click OK.
12. A new worksheet, called Scenario Summary, is automatically cre-
ated as shown in Figure 2.49. This worksheet shows a table with the
assumptions of the Changing cells and the NPVs for the Low, Base,
60 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
and High Case scenarios. The actual worksheet with the Scenario
Manager settings is given in Figure 2.48 (Chapter 2 Workbook in
the folder).
Figure 2.50 The Solver function under the Data tab of the Excel
Ribbon
Four different problems are solved here using Excel to show the vari-
ety of problems Solver can solve.
X1 X2 X3 X4 X5 X6 750,000
X1 X2 X4 X6 > $375,000
X2 X3 X5 < $262,500
Since none of the variables in the model can assume a value of less than
zero, the following non-negativity constraint shall be met.
Figure 2.51 shows how this problem is setup in Excel to be ready for
the Solver. The first step in using Solver is to setup the model.
The objective function is entered in Cell B8 as SUMPRO-
DUCT(B2:B7,$H2:$H7). The H2:H7 are absolute so they will not
change if we copy this function to other cells.
Copy Cells B8 to E8 and G8
Figure 2.51 Setting up the problem before the Solver can be used
Figure 2.52 The Solver Parameters dialog box for the problem in
Figure 2.51
Figure 2.53 Final solution of the problem in Figure 2.51 after Solver
is applied
9. The SOLVER Results dialog box (as shown in Figure 2.54) appears
showing that solver found a solution and all constraints are satisfied.
Sometimes it will show that a solution is not found or one or more
constrains are not satisfied. In this way you may click OK and click
on Solve again. If you are not satisfied with the result, you may
cancel the run so that the numbers existing in your worksheet will
not change.
10. Click OK—The process is complete.
q = qi (1 + bDi t )
−1/b
(1)
qi b
Gp = ⎡q 1−b − q1−b ⎤⎦ (2)
(1 − b ) Di ⎣ i
where
qi Initial rate, the rate at which the well initially starts producing
Di The initial rate at which the production declines (%)
b The hyperbolic exponent which controls the shape of the curve
b 0 : Exponential decline
b > 0 < 1 : Hyperbolic decline, but it could be more than 1
b 1 : Harmonic decline
t Elapsed time (days or months)
q Production rate at time t
Gp Cumulative production during period of time (days, months, or
years)
The problem is setup as shown in Figure 2.55. The following steps are
used to construct the worksheet.
Figure 2.57 Final result of the production history match of Figure 2.55
USING EXCEL’S DATA TAB 71
7. The Cell E36 can now be extended into the future to give the future
production forecast of this well. Normally, the production is fore-
casted until the q = economic limit.
8. Figure 2.58 graphically shows the actual production and the matched
production forecast.
6. Enter =E2*M14 in Cell G2. This picks the NPV of the selected
project from Figure 2.60.
a. Cell E3 =E3*M19
b. Cell E4 =E4*M24
c. Cell E5 =E5*M29
7. Enter the budget constraint of $2,800 in Cell B6.
8. Enter =SUMPRODUCT(D2:D5,E2:E5) in Cell E6.
9. Enter =SUM(F2:F5) in Cell F6 and copy it to G6.
10. Click on Data Solver.
a. Set Objective: E6
b. To: Tick Max
c. By Changing Variable Cells: E2:E5
d. Subject to the Constraints:
i. E2:E5 = Binary To make sure that we get only 1 or 0 and
no fractions.
ii. F6 <= B6 This is the budget constraint to make sure that
the CAPEX of the selected investments in Cell F6 is not more
than the budget constraint in Cell B6.
c. Select a Solving Method: GRG Nonlinear.
d. Click on Solve.
Presenting Information
Using Charts
Visual presentation of our work is extremely important. As per the pop-
ular saying “picture is worth a thousand words,” that is, we can condense
lot of useful information in clear and meaningful charts to convey our
message. Remember that management does not have time to go over
your worksheets with hundreds of rows and hundreds of columns and
spread over probably 20 worksheets. Management is normally interested
to see the bottom-line results that they can use for decision making. This
objective can be very easily achieved in pictorial presentation (charts and
to-the-point bullet points in our presentations).
Most Excel users are very familiar with the basic charting of data. Here
we will go over some advanced concepts to enable us develop dynamic
charts, that is, dynamic titles (chart and axis), dynamic legends, dynamic
data capturing (if more data is added to the same chart), and so on. We
will also go through some features of using charts for forecasting future
scenarios while using historical data.
Guidelines
Consistent formatting of charts is very important to improve the overall
esthetic of the presentation. I always develop one chart template and then
keep on using this template throughout the presentation or document.
This gives more balanced look to the presentations or documents. Once
you have a template then all you have to do is change the (a) data source
and (b) change chart type. In addition, if you develop dynamic charts
then the changes will be minimal. Given below are some basic guidelines
to follow when building charts.
78 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
the data in descending order. Figure 3.2 shows the same graph as
in Figure 3.1 but the Net Present Value (NPV) is not in any order
(decreasing or increasing). The projects on the Y-Axis are Project 4 to
Project 1 instead of Project 1 to Project 4.
Figure 3.2 Horizontal bar chart showing projects’ NPV in Figure 3.1
8. For sequential data, such as monthly revenue or cost per year, order-
ing data chronologically makes more sense, that is, starting from Jan-
uary and ending in December.
9. Chart title—Use a descriptive and self-explanatory title for the chart.
The title makes it easier for the viewer to know what the chart is
about.
10. Axis titles—If the axis titles don’t fit horizontally in a certain type of
chart then try another type of chart. It is not recommended to have
the axis titles vertical or at an angle. This can make data interpreta-
tion laborious and vulnerable to misinterpretation.
11. Thousands separator—If you have data greater than 999, use the
number format with thousands separator. This is also recommended
for the rest of the worksheets. If your data in the table is with thou-
sands separator, the chart will automatically pick that format.
12. Dynamic titles—Make your chart with dynamic axis titles, dynamic
chart title, and dynamic legends. In this way when any headings in
the chart change, the chart is automatically updated. For example,
we are plotting projects versus their respective NPV at 10 percent
discount rate. Therefore, the X-Axis shows that but if the discount
80 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
rate in the worksheet changes then the graph will change but the
axis title will not change if it is not linked to the discount rate in the
worksheet. We will later show how to do this.
13. Covered area—Try to cover at least 75 percent of the chart area
14. Primary and secondary axis—The gridlines for the primary axis and
secondary should overlap to make it easy for the viewer to reconcile
the information with the axis values.
Bubble Chart
Bubble charts are used to show correlation between three variables, that
is, X, Y, and Z. We have four projects, each project has a certain capital
expenditure requirement and generates a certain NPV. We can show this
information in two different ways. The data is given in Table 3.1.
Figure 3.3 shows a bar chart of NPV versus CAPEX. The project
names are added manually. The same data can be plotted in a bubble
Figure 3.3 Bar chart showing relationship between CAPEX and NPV
PRESENTING INFORMATION USING CHARTS 81
chart where project name, CAPEX, and NPV are collectively displayed
as shown in Figure 3.4. This bubble chart is more descriptive and clearly
shows the relationship between the projects, CAPEX, and NPV.
Dynamic Charting
Dynamic charting means that whenever you change data range (delete or
add more data), axis titles, chart title, legends, and so on, the charts are
automatically updated. Creating dynamic charts requires advanced skills
beyond the ordinary charting skills. It requires the source data to be a
dynamic range. There are basically two methods available that I use most
of the time, that is, the table method and the formula method.
The data ranges for Figure 3.3 are shown in Figure 3.5. In ordinary
situation we will drag the range down number of cells required to accom-
modate additional data as shown in Figure 3.6. Now when we enter data
in Cells A6:C6, the chart in Figure 3.3 will be updated with the new
range of data. The new data range and the resulting chart are shown in
Figures 3.7 and 3.8, respectively.
We can do the same exercise by using Excel’s table function. The first
step is to create the table. This can be done with the existing data as shown
in Table 3.1 and Figure 3.5. The following steps will be used.
82 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Figure 3.5 The data range used in the bar chart in Figure 3.3
Figure 3.6 Manually extending the range of data to be plotted for the
chart in Figure 3.5
Figure 3.9 The Create Table dialog box under the Table tab
4. Click OK and Excel will format the data range as a table shown in
Figure 3.10.
84 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Now you can just add more data in Row 7 and the chart in Figure 3.8
will be automatically updated. This method has one disadvantage though,
if you delete data in Row 6, the bar in the chart will disappear but it will
create empty space in the Chart. This can be fixed by dragging the last row
of the table one row upward. This limitation is with bar charts, the line
charts will not have this limitation.
Figure 3.14 Select Data Source dialog box to edit the data series
PRESENTING INFORMATION USING CHARTS 87
(a)
(b)
(a)
(b)
Figure 3.16 Axis labels dialog box to edit the horizontal axis
Waterfall Chart
When making projects’ economics or financial statements or income
statement presentations to management, many times we are asked “why
there is difference in the profitability indicators or net income or cash
flow you are presenting today vs. what you presented few months ago?”
PRESENTING INFORMATION USING CHARTS 89
Follow the following steps to generate the waterfall chart. These methods
are used with Excel 2010 and 2013. Excel 2016 has a built-in waterfall
chart function that we will also use later.
3. Click on the bottom right corner of B8 and drag it to J8. This will
highlight Columns B to J and complete the raw chart as shown in
Figure 3.20.
The same dataset is used to generate a waterfall chart. The following steps
will be followed.
Figure 3.22 Excel data for the waterfall chart (Method No. 2)
Figure 3.23 Final waterfall chart resulting from using Method No. 2
94 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
3. The Excel table as shown in Figure 3.24 can also be used. In this
version the START LRMC ($7.68/MMBtu) and the END LRMC
($4.02/MMBtu) are in Column B (B2 and B9, respectively) and
identified as PILLARS.
a. The FALL and RISE are given in Cells C2:D9.
b. The formula in Cell C3 is B2 D3 E3.
c. The formula in Cell C4 is C3 D4 E4 and it is copied down
to C8.
Tornado Diagram
Tornado diagrams or tornado chart are modified version of horizontal
stacked bar charts. It is one of the classic tools used to assess the sensitivity
of various variables to the profitability of the project or investment. The
Tornado diagram is used by decision makers to have a quick overview
of the risks involved. In other words a Tornado diagram or chart shows
financial analysis for a project or investment.
There are add-in tools available that will help in construction Tornado
diagrams but it can also be easily constructed using Excel’s graphing capa-
bilities. The following steps are required to get data ready for constructing
a Tornado diagram.
likely values which are considered as the most likely case in the best
professional judgment of the analyst.
2. Then vary each variable by ±25 percent and calculate the profitabil-
ity indicators. For example if the base CAPEX is 1,000 MM$ then
the –25 percent would be 750 MM$ and the 25 percent would be
1,250 MM$. In this way you will get three profitability indicators
(let us say NPV at a certain discount rate). The three NPVs will be
the Base Case NPV, NPV resulting from 25% CAPEX, and NPV
resulting from 25 percent CAPEX.
3. In some cases the ±25 percent may not be feasible. For example infla-
tion rate of 1, 2, or 3 percent per year. On the other hand, tax rate of
30, 35, or 40 percent, and so on.
the formula =IF(B3>D3,B3 D3,C3 D3) in Cell F3 and copy it Cell F7.
Now follow the following steps to construct the Tornado diagram.
The final Tornado diagram is shown in Figure 3.28. The Tornado dia-
gram tell us that CAPEX, Oil Price, and Discount rate are most sensitive
to the NPV. Any small variation in these can significantly increase or
decrease the NPV. The OPEX and inflation are not very sensitive to the
profitability. In short, the wider the bars more sensitive are these variables
98 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
to profitability. The narrower the bars less sensitive are these variables to
profitability.
There are other variations to this typical Tornado diagram in which
the negative impact of profitability is shown on the left side of the base
and positive impact is shown on the right side of the base. Construct-
ing the diagram is same on the setting up the data is slightly different.
This kind of Tornado diagram shows the negative and positive impact of
changes in variables on the profitability. Figure 3.29 shows the NPVs for
changes in various variables. The Base Case NPV is calculated based on
15 percent discount rate.
Spider Diagram
Spider diagram is another presentation for the sensitivity assessment of
various variables on the profitability. It gives the same message as the
Tornado diagram but in a line chart rather than the bar chart.
PRESENTING INFORMATION USING CHARTS 101
The data of Figure 3.26 is used to generate a Spider diagram. The dis-
count rate and inflation are not included in the Spider diagram because
these were not varied by ±25 percent. The X-Axis will be the variation in
Variables. The Spider diagram is shown in Figure 3.32.
In the Spider diagram, the steeper the slope of the line more sensitive
this variable is to the profitability. The shallower the slope of the line less
sensitive this variable is to the profitability. The OPEX line is with very
shallow slope showing that OPEX is not very sensitive to profitability.
The Tornado diagram also showed a very narrow bar for the OPEX, con-
firming what the Spider diagram is showing.
Multivariable Cross-Plots
Creating multivariable charts are becoming very popular. These charts
help in correlating variables in all the four quadrants of a graph and the
final result is obtained in the last quadrat. The first thing to do is, of
course, the sensitivity analysis on the desired variables. An example is
presented here that correlates Drilling Cost per well with the respective
LRMC (long range marginal cost) with the reserves per well. The result-
ing LRMC is then plotted against the LRMC of various facilities CAPEX
(pipeline and gas plant capital expenditure.
102 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Table 3.3 shows the data obtained from sensitivity analysis of various
drilling costs versus the reserves per well.
Table 3.3 LRMC ($/MMBtu) for various drilling costs and reserves/
well (Base facility CAPEX = 625 MM$)
Drilling cost/ 7.33 10.99 BSCF/ 21.40 BSCF/
well MM$ BSCF/well well well
10 6.97 5.02 3.17
15 8.35 5.95 3.67
20 9.72 6.88 4.18
25 11.09 7.81 4.69
30 12.47 8.74 5.19
Table 3.4 shows another set of sensitivities, that is, various facilities’
Capital Expenditures (CAPEX) versus the reserves per well.
Now we build the first chart, Scatter Chart, for the data in Table 3.3
as we will normally do. Highlight Cells A3 to D7 Insert Scatter
Chart. The chart is created, format the chart as shown in Figure 3.33. The
X-Axis is the drilling cost and the Y-Axis is the Long Range Marginal Cost
(LRMC in $/MMBtu), also referred to as the breakeven gas price. Note
that the Y-Axis is not labeled yet as the LRMC will be read on the X-Axis
in the second quadrant.
Add linear trend lines through the data points in Figure 3.33.
Now add the data of Table 3.4 to the same chart. Note that the LRMCs
in Table 3.4 are not negative. Since they will be plotted in the second quadrant
PRESENTING INFORMATION USING CHARTS 103
Figure 3.33 Correlation between the drilling cost per well vs. the
reserves per well
on the X-Axis, their sign is changed from positive to negative. This is a very
important point to remember.
Right click on the chart Select Data Add X-Axis is G3:G7
and Y-Axis is F3:F7 OK.
Repeat the same step for all the other CAPEX (H3:H7 vs. F3:F7,
I3:I7 vs. F3:F7 and J3:J7 vs. F3:F7). Add trend line through each data
series in the second quadrant. The raw chart is shown in Figure 3.34.
Now we need to hide the Y-Axis labels and overwrite the negative X-Axis
labels. Follow the following step to hide the Y-Axis. I have removed the
legend from Figure 3.33 and instead put them on the respective lines in
the chart as shown in Figure 3.34.
Right click on the Y-Axis Format Axis Labels Label Position
NONE.
Now hide the negative numbers on the X-Axis in the second quadrant
and make the axis label for it. The axis label is done by using the following
step.
Click on Insert Shapes Rectangle (draw a rectangle) Right click
on the Rectangle Click on Add text Enter 15, 10 and 5 Change
the Fill color Remove the lines. Move the Rectangle over the negative
X-Axis labels and format to make sure the labels represent the major axis.
Repeat the above step to insert the X-Axis title for the second quad-
rant. Alternatively, edit the existing X-Axis title “Drilling Cost per Well,
MM$” by entering “LRMC, $/MMBtu” before it. And format the
placing of the title.
Figure 3.35 shows the final version of the multivariable cross plot. It
correlates the (a) drilling cost per well, (b) reserves per well, and (c) facili-
ties’ CAPEX. To read the LRMC, the following steps are required.
Figure 3.35 Final version of the multivariable cross plot for the data
in Tables 3.3 and 3.4
PRESENTING INFORMATION USING CHARTS 105
So if the drilling cost is 15 MM$ per well, the reserves per well are
10.99 BSCF and the facilities CAPEX is 1,525 MM$ then the LRMC will
be about $7.0/MMBtu (as shown in Figure 3.35). At facilities’ CAPEX
of 625 MM$, the LRMC from the chart would be approximately $6/
MMBtu (the actual $5.95/MMBtu).
In the same way, LRMCs at another set of variables can be added in
the third and fourth quadrants. Instead of the LRMC, NPVs can also be
correlated in the same way.
Interactive Chart
In this section we will show how to select data for charting using the Form
Controls or ActiveX Controls such as the Check Box (Form Control) or
Radio Button (Form Control) discussed in Chapter 1.
Figure 3.36 shows total revenue, cost of revenue and operating income
or loss for Exxon Mobile for 2014 to 2016. We want to generate an inter-
active chart to be able to show all or some of the variables in the chart
using the Form Controls.
Cells B3:D5 in Figure 3.36 show the annual total revenue, cost of
revenue and operating income or loss of Exxon Mobile Corporation. In
Cells B7:D7 we enter the Check Box (Form Controls) for each of these
parameters (the procedure is explained in Chapter 1). Link the outcome
of each Check Box to the cells underneath (i.e., Cells B8, C8, and D8).
These cells will show TRUE if the Check Box is ticked and FALSE if the
Check Box is not ticked. The TRUE means plot this parameter and the
FALSE means do not plot the parameter.
Enter the formula IF($B8 TRUE,B3,NA()) in Cell B10 and drag
it to Cell D10. Now highlight Cells B10:D10 and drag them down to
Cells B12:D12. The NA() in the formula enters #N/A if the selection is
FALSE. Whenever, you do not want to plot any of the variables, replace
these by #N/A. You can use this in manual plotting as well.
The interactive chart is now ready as shown in Figure 3.37. Since only
the first two parameters are ticked, these are shown in the chart. You can
also do similar chart where you can select the year for which you want to
show the data, that is, you can select to show data for 2014 only or 2014
and 2016 only and so on.
on the Y-Axis Title Enter the formula ‘Fig 3-36’!$A$9 in the For-
mula Bar (OR Enter “=” and link Cell A9 in the Formula Bar).
This becomes very handy when variables change. For example, you
are plotting discounted net cash flow at 10 percent discount rate versus
time. The X-Axis title in your chart shows years and the Y-Axis title is
manually entered to show “Discounted Cash Flow at 10 percent, MM$.”
Now if you change the discount rate in the input sheet to 15 percent,
the chart will be updated but the Y-Axis title will not be updated.
However, if the Y-Axis title is linked to a cell where the heading is “Dis-
counted Cash Flow at 10 percent, MM$” then the axis title will automat-
ically change. The heading has to be entered in a cell as “Discounted
Cash Flow at “&A1*100&”%, MM$” assuming the discount rate is
given in Cell A1.
Correlating Variables
Excel has built-in options to show correlations between variables. This
feature is available in scatter charts. Right click on the Data Series
Add Trendline Select Trendline Option Tick Display Equation on
Chart Tick Display R-Squared Value on Chart. The Display Equation
on chart will show correlation between the X-Axis data and Y-Axis data.
The R-Squared (R2) shows the correlation of correlation (goodness of fit)
between the data. The R2 1 is perfect correlation and R2 0.5 is poor
correlation (not very strong correlation). Following are the Trendline
Options available in Excel.
1. Exponential
2. Linear
3. Logarithmic
4. Polynomial (this could be 2nd order, 3rd order polynomial, and so on)
5. Power
6. Moving Average
equations are given on the chart. These are generated by the Trendline.
The Trendline equations also provide the slope and intercept of the lines.
The slope for Set 1 data is 1.5 with intercept 12.5. The slope of Set 2 data
is –1.5 with intercept of 87.5.
In some cases the chart may not be required but the correlation has to
be determined in order to use the historical trend to forecast the future.
Following are some of the Excel functions that can be used to find the
correlation between sets of data and other parameters such as slope, inter-
cept (equation of the correlation).
CORREL(array1, array2)
array1 the X-Axis data and array2 Y-Axis data. The Excel
worksheet (Fig 9-38) shows the use of CORREL function in Cells
B7 and C7 for Set 1 and Set 2 data, respectively. The formula
CORREL(A3:A6,B3:B6) is entered in Cell B7 to calculate R2 for
the data Set 1 and CORREL(A2:A6,C2:C6) in Cell C7 to calculate
the R2 for data Set 2. These calculations are shown in Figure 3.39.
PRESENTING INFORMATION USING CHARTS 109
A line with negative slope will show negative R2 and the line with
positive slope will show positive R2. The message is same, that is, how
strong is the relationship between the two datasets. The negative R2
only shows that the line is sloping downward (similar to the line of
Set 2 in Figure 3.38).
2. The TREND and FORECAST Functions
As mentioned above the TREND and FORECAST functions of
Excel are used to forecast the future based on historical linear trend.
The fitting of a straight line using the method of least squares (linear
regression) to the datasets.
The syntax for these two options is:
TREND(known_y’s, [known_x’s], [new_x’s], [const])
FORECAST(x, known_y’s, [known_x’s])
Following are the arguments for these two functions.
a. Known_y’s—A set of known Y-Axis values in the dataset. The
data can be in a ROW or COLUMN.
b. Known_x’s—A Set of known X-Axis values in the dataset. The
number of data points in both Y-Axis and X-Axis data must be
same (i.e., pairs). The array Known_x’s can include one or more
sets of variables.
c. New_x’s or x—New X-Axis values for which the corresponding
Y-Axis values have to be forecasted.
d. Const—Could be TRUE or FALSE. The FALSE means to forces
the correlation through intercept 0. The TRUE means to calcu-
late the intercept of the correlation. The default is TRUE.
110 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
example, how would calculate the slope and intercept of a set of data
when the dimensions could change, that is, adding or deleting data
from the range specified in the SLOPE and INTERCEPT function.
Figure 3.40 shows a dataset in which the SLOPE and INTER-
CEPT can be calculated for up to eight data pairs. The cells where
there is not data, enter NA() function in those cells as shown in
Figure 3.40.
INTERCEPT(C2:C6,A2:A6) – INTERCEPT(B2:B6,A2:A6)
Intersection =
SLOPE(B2:B6,A2:A6) – SLOPE(C2:C6,A2:A6)
CHAPTER 4
Automating Worksheets
In this chapter we will discuss the use of Macros and Visual Basic for
Application (VBA), that is, automating the execution of tasks requiring
many repetitive steps.
repetitive steps in the Macro because the Macro Recorder captures almost
every move we make during the recording. These redundant and repet-
itive steps have to be edited. It is really not very difficult to understand
the moves (VBA Code) recorded by the Macro Recorder and identify and
edit the redundant or repetitive steps. Now the Macro is ready to perform
the required task at a click of a button.
Once the Macro is developed it is then assigned to a Form Control
button. So Clicking on the button automatically runs the Macro. Alter-
natively, the Macro can also be run manually. The following few guide-
lines need to be kept in mind when developing Macros.
1. Macros are range specific, that is, performing a set of tasks in a spec-
ified range (Rows and Columns) in Excel. If the Cells are altered by
adding or deleting Rows, Columns, or Cells then the Macro will give
error. The Macro will stop running when it does not encounter the
recorded Cells.
2. A very long Macro, handling multiple tasks, should be split into sev-
eral smaller Macros to avoid mistakes and enabling debugging easier.
Recording a Macro
As mentioned above, this option is mostly for the people who are not
experts in Visual Basic programming language. The expert developers can
write the VBA code without relying on this option. A Macro or VBA
code lists all the steps required to solve a certain problem especially if the
problem requires repetitive calculations.
The Macro icons (Macros and Record Macro) are given under the
Developer tab of the Excel Ribbon as shown in Figure 4.1. The Macro
icon can also be accessed from the VIEW tab on the Excel Ribbon as
Figure 4.1 The Macro icons under the Developer tab of Excel’s
Ribbon
AUTOMATING WORKSHEETS 115
shown in Figure 4.2. By clicking on this icon a dropdown list will appear
which will show (a) View Macros, (b) Record Macros, and (c) Use Relative
References.
Figure 4.2 The Macro icon under the View tab of Excel’s Ribbon
Figure 4.4 Manually using Goal Seek to find out the loan amount for
a specified monthly payment
Click of a button. The Macro will follow the Steps 1 to 7 listed above. The
following steps are followed to develop a Macro.
Figure 4.6 The Record Macro dialog box for recording a Macro
d. Store Macro in: Gives you option to (a) store the Macro in
Personal Macro Workbook, (b) New Workbook, or (c) This
Workbook. If the Macro is going to be used in the workbook
only then it is better to store it in This Workbook.
e. Description: Here you can enter brief description of what the
Macro will do.
3. Place the cursor in Cell B5 if it is not already in the Cell.
4. Click on DATA tab.
5. Click on What If Analysis in the Data Tools tab.
6. The Goal Seek dialog box appears.
a. Set cell: Enter B5 if it is not already there.
b. To value: Enter –2000.
c. By changing cell: Enter B1.
7. Click OK.
8. Goal Seek Status dialog box appears showing the Target value and
Current value. Click OK.
9. Click on Developer tab or View tab.
10. Click on Stop Recording.
118 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
1. Run Macro: Click on Run to execute the Macro and perform the
desired calculations.
2. Step Into: To see the Visual Basic code generated by the Record
Macro.
3. Edit: Click on Edit to open the Code.
4. Delete: To delete any of the Macros. Highlight the Macro to be
deleted and click on Delete.
5. Options: Gives you option to assign Short Cut Key and Macro
description.
To view the Macro code, highlight the Macro and click on Step Into.
The Macro code for the recorded Macro is shown in Figure 4.8.
Save the workbook. When you save the Workbook just by clicking on
SAVE, it will give you error message and will alert you that the workbook
has a Macro and you cannot save it as regular workbook. Click on OK
AUTOMATING WORKSHEETS 119
Figure 4.8 The Visual Basic code for the recorded Macro
on the error message and then click on SAVE AS. A dropdown list will
appear showing various files options. Select Save As “Excel Macro-Enabled
Workbook.” All Macro-Enabled workbooks will have an exclamation mark
“!” in the right hand corner of the Excel icon. This exclamation mark dis-
tinguishes between the Workbooks with and without macros.
If you are not prepared or if you do not follow the precise steps
required to solve a problem and you start recording, many unnecessary
steps will be recorded by the Macro recorder. Also while you are recording
a Macro, the steps required to solve the problem are followed correctly
and recorded but you forget to Stop Recording. Whatever you do until
the Macro recording is stopped, all steps will be recorded which will not
be relevant to the problem you are trying to solve. Figure 4.9 shows a
Macro to solve the same problem as in Figure 4.8 but it has several unnec-
essary steps.
When you see all these extra steps, you have to identify the steps that
are really needed and then delete the extra steps that are not required.
Sometimes the extra steps may not affect execution and function of the
Macro but most of the time it could be detrimental and perform actions
that are not required. In Figure 4.9 (Macro2), the first five lines and the
last two lines of the code are redundant and shall be deleted. In this par-
ticular case the first five lines will not affect the calculation but it will just
make the Macro go through few unwanted steps. The last two lines will
affect because they will take you to Figure 4.9 after the Macro solves the
problem.
The start and end of the Macro are defined by (a) Sub Macro1() and
(b) End Sub, respectively. Inside these two we can also call another Sub
Macro and when that Macro reaches its End Sub then it comes back to
the same spot in the Macro where it was asked to go to the other Macro.
Figure 4.10 Dropdown List for Assigning Macro to the Form Control
Button
1. Cell C2: Enter the formula B2*L$2 and drag it to Cell C8.
2. Cell D3: Enter the formula B2*L$3 and drag it to Cell D8.
3. Repeat these steps for Cells E4, F5, G6, H7 and I8.
4. Cell K2: Enter the formula SUM(C2:I2) and drag it down to Cell K8.
5. Now we are ready to record a Macro to perform Goal Seek on each
Cell.
a. Click on Developer tab Record Macro Macro3 (Macro3
will be assigned automatically since there are already two Macros
before from Figure 4.9).
b. Click on Data What If Analysis Goal Seek.
c. Set Cell: to K2.
d. To Value: 30000.
e. By Changing Cell: L2.
f. Repeat these steps for Cells K3, K4, and K5.
g. Click on Developer tab Stop Recording.
Figure 4.13 Figure 4.12 after the calculations are performed using
Macro3
Sub Macro3()
‘
‘ Macro3 Macro
‘
‘
Range(“K2”).GoalSeek Goal: 30000, ChangingCell: Range(“L2”)
Range(“K3”).Select
124 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
1. The Macro is not flexible, that is, if the targets are changed—the
matched target will not change because the Macro shows hard-coded
target revenues. We can add three more lines of Code to address
Ranges K6, K7, and K8 by copying one of the lines and paste it three
times after the last line. We should then edit the three lines to make
sure the Range, Goal, and Changing Cell references are correct. This
will add more flexibility but then it will give error or incorrect num-
ber of wells if the target cells are empty.
2. There are redundant steps in the Macro.
3. The Macro will not calculate the matched target if we enter another
target revenue in Cell J6.
We can edit the Macro to fix some of the above problems as shown
below. In the edited version, the redundant codes are deleted and the
additional target cells are manually added and edited. The revised Macro
is shown below.
Sub Macro3()
‘
‘ Macro3 Macro
‘
‘
Range(“K2”).GoalSeek Goal: 30000, ChangingCell: Range(“L2”)
Range(“K3”).GoalSeek Goal: 29000, ChangingCell: Range(“L3”)
Range(“K4”).GoalSeek Goal: 28200, ChangingCell: Range(“L4”)
Range(“K5”).GoalSeek Goal: 27560, ChangingCell: Range(“L5”)
AUTOMATING WORKSHEETS 125
The Macro still has two limitations (a) hard-coded Goals and (b) the
Macro will not stop if the targets are empty. In the Macro below the hard
coded targets are replaced by the Range Cell reference [Range(“J2”) to
Range(“J8”)] as shown below.
Sub Macro3()
‘
‘ Macro3 Macro
‘
‘
Range(“K2”).GoalSeek Goal: Range(“J2”),
ChangingCell: Range(“L2”)
Range(“K3”).GoalSeek Goal: Range(“J3”),
ChangingCell: Range(“L3”)
Range(“K4”).GoalSeek Goal: Range(“J4”),
ChangingCell: Range(“L4”)
Range(“K5”).GoalSeek Goal: Range(“J5”),
ChangingCell: Range(“L5”)
Range(“K6”).GoalSeek Goal: Range(“J6”),
ChangingCell: Range(“L6”)
Range(“K7”).GoalSeek Goal: Range(“J7”),
ChangingCell: Range(“L7”)
Range (“K8”).GoalSeek Goal: Range(“J8”),
ChangingCell: Range(“L8”)
End Sub
Now only one limitation is left, that is, to stop the calculations when
the Macro encounters empty target cells. This limitation is eliminated by
adding IF statement in the Macro as shown below. The If ActiveSheet.
Range(“J2”).Value = ”” Then Exit Sub tells the Macro that if the Target
126 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
Cell is empty then Exit the Macro. The “Sub” is an abbreviation for
Subroutine.
Copy the following Macro Developer Macros Edit Paste
Macro4 at the end of the existing Macros.
Sub Macro4()
‘
‘ Macro4 Macro
‘
‘
If ActiveSheet.Range(“J2”).Value ”” Then Exit Sub
Range(“K2”).GoalSeek Goal: Range(“J2”),
ChangingCell: Range(“L2”)
If ActiveSheet.Range(“J3”).Value ”” Then Exit Sub
Range(“K3”).GoalSeek Goal: Range(“J3”),
ChangingCell: Range(“L3”)
If ActiveSheet.Range(“J4”).Value ”” Then Exit Sub
Range(“K4”).GoalSeek Goal: Range(“J4”),
ChangingCell: Range(“L4”)
If ActiveSheet.Range(“J5”).Value ”” Then Exit Sub
Range(“K5”).GoalSeek Goal: Range(“J5”),
ChangingCell: Range(“L5”)
If ActiveSheet.Range(“J6”).Value ”” Then Exit Sub
Range(“K6”).GoalSeek Goal: Range(“J6”),
ChangingCell: Range(“L6”)
If ActiveSheet.Range(“J7”).Value ”” Then Exit Sub
Range(“K7”).GoalSeek Goal: Range(“J7”),
ChangingCell: Range(“L7”)
If ActiveSheet.Range(“J8”).Value ”” Then Exit Sub
Range (“K8”).GoalSeek Goal: Range(“J8”),
ChangingCell: Range(“L8”)
End Sub
However, can you imagine how the code will look like if you had to
match targets for 20 years or so? The code will be very crowded and may
be subject to other logic errors because it becomes too cumbersome to
edit properly.
This problem can also be solved by incorporating all the steps in a
nested IF Loop as shown in Macro5 below.
Sub Macro5()
‘
‘ Macro5 Macro
‘
‘
Dim i As Integer
For i 2 To 8
If ActiveSheet.Range(“J” & i).Value ”” Then Exit Sub
Range(“K” & i).GoalSeek Goal: Range(“J” & i), ChangingCell:
Range(“L” & i)
Next
Range(“A1”).Select
End Sub
Now copy the above Macro (Macro5) and paste it in-between the Sub
Macro5() and End Sub. Assign this Macro to another Form Control
Button in the same worksheet.
The final worksheet is shown in Figure 4.15 with all the Macros devel-
oped in this section.
You can also develop code for nested loops as shown below.
Sub MacroX()
‘
‘ MacroX Macro
‘
Dim i As Integer, j As Integer
For i 1 To 2
For j 1 To 5
Cells(i, j).Value WorksheetFunction.RandBetween(20, 100)
Next j
Next i
End Sub
Sub Macro6()
‘
‘ Macro6 Macro
‘
‘
SolverOk SetCell: “$G$8”, MaxMinVal: 1,
ValueOf: 0, ByChange: “$B$7:$F$7”, _
Engine: 2, EngineDesc: “Simplex LP”
SolverAdd CellRef: “$B$7:$F$7”, Rela-
tion: 5, FormulaText: “binary”
SolverAdd CellRef: “$I$2:$I$5”, Rela-
tion: 1, FormulaText: “$H$2:$H$5”
SolverOk SetCell: “$G$8”, MaxMinVal: 1,
ValueOf: 0, ByChange: “$B$7:$F$7”, _
Engine: 2, EngineDesc: “Simplex LP”
130 TIPS & TRICKS FOR EXCEL-BASED FINANCIAL MODELING
This code, as is, will not work. Lot of editing is required to make it to
function correctly. Following is the revised Code. Note, that many dialogs
are same but with some redundancy.
Sub Macro7()
Application.Run “SolverReset”
Application.Run “SolverOK”, “$G$8”, 1, 0, “$B$7:$F$7”, _
2, “Simplex LP”
Application.Run “SolverAdd”, “$B$7:$F$7”, 5, “binary”
Application.Run “SolverAdd”, “$I$2:$I$5”, 1, “$H$2:$H$5”
Application.Run “SolverSolve”, True
Range(“G8”).Select
End Sub
1. Each line in the Code must start with Application.Run, this is telling
Excel that Solver is an Application. The Macro recorder does not
insert this argument in the Code in Macro6
2. SolverOK, SolverSolver, and SolverAdd are the same in both Macros
but in Macro7 each is enclosed in double quotes while in Macro6
they are not enclosed in double quotes.
3. In Macro6 the other arguments in the Solver Parameters dialog box
are referred to by sequence number, that is, no description such as
MaxMinValue, ValueOf, ByChange, FormulaText, and so on. As
shown in Figure 4.16, Max 1, Min 2, Value Of 3 and the value
is zero if Max or Min are selected otherwise the required value has
to be entered.
AUTOMATING WORKSHEETS 131
Debugging a Macro
When a Macro is developed, it may sometimes have errors in it and these
errors need to be corrected. When a Macro with errors is executed, it
will stop execution when it reaches a Code that is not correct or it is
not recognized by Excel. The Microsoft VBA error message, as shown in
Figure 4.18 will appear. Click on OK, you will be taken the VBA Code
and the Code that has error will be highlighted in yellow. This is where
the Macro execution stopped.
• a one-time purchase,
• that is owned forever,
• allows for simultaneous readers,
• has no restrictions on printing, and
• can be downloaded as PDFs from within the library community.
Our digital library collections are a great solution to beat the rising cost of textbooks. E-books
can be loaded into their course management systems or onto students’ e-book readers.
The Business Expert Press digital libraries are very affordable, with no obligation to buy in
future years. For more information, please visit www.businessexpertpress.com/librarians.
To set up a trial in the United States, please email [email protected].
THE BUSINESS Tips & Tricks for Excel-Based
MIAN
EXPERT PRESS
DIGITAL LIBRARIES
Financial Modeling
A Must for Engineers & Financial Analysts,
EBOOKS FOR Volume II
BUSINESS STUDENTS
Curriculum-oriented, born- M. A. Mian
digital books for advanced The purpose of this work is to show some advanced concepts
business students, written related to Excel based financial modelling. Microsoft Excel™
by academic thought