0% found this document useful (0 votes)
62 views10 pages

Sample Pages: Excel / VBA For Business & Accounting

This document provides an overview of a textbook on using Excel and VBA for business and accounting applications. Chapter 1 introduces programming concepts like constants, variables, and assignment which are fundamental to all computer languages like VBA. It explains that constants are fixed values while variables can take on different values, and that a constant can be assigned to a variable but not vice versa. The key to programming is telling the computer exactly what to do in simple steps with no uncertainty.

Uploaded by

Susanto Yang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views10 pages

Sample Pages: Excel / VBA For Business & Accounting

This document provides an overview of a textbook on using Excel and VBA for business and accounting applications. Chapter 1 introduces programming concepts like constants, variables, and assignment which are fundamental to all computer languages like VBA. It explains that constants are fixed values while variables can take on different values, and that a constant can be assigned to a variable but not vice versa. The key to programming is telling the computer exactly what to do in simple steps with no uncertainty.

Uploaded by

Susanto Yang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Excel / VBA for

Business & Accounting

s
Analytical tools for improved decision making

ge
pa
SECOND EDITION
e
pl

Steven Chapra, Paul Blayney and Abdul Razeed


m
Sa

9781488624872_FM.indd 1 6/25/18 10:56 AM


Contents

1 Introduction 1

Overview of book  1
The key to programming and the concept of assignment  1

2 FSA and basic spreadsheet structure  5

s
Financial statement analysis (FSA)  5
Basic spreadsheet structure (separate data section)  5

ge
Cell referenced formulas (no hard coding)  6
Enabling macros  6
Changing macro security  7
Creating a FSA spreadsheet  7
pa
3 Cost Behaviour and VBA fundamentals  9

Cost behaviour  9
e
Opening the Visual Basic Editor (VBE)  10
The VBE Project Explorer  10
pl

Creating / inserting a module  11

4
m

Cost Volume Profit Analysis (CVP) & VBA fundamentals  13

Cost-volume-profit (CVP) analysis  13


Sa

Creating a subroutine  13
Declaration of variables  14
Assignment of values to variables  15
Displaying values with a message box (MsgBox)  16
Creating a cost behaviour subroutine  17
Creating a CVP subroutine  17
Introduction to the Input Box  17

5 Cost Volume Profit Analysis (CVP) & VBA decisions (IF’s)  21

Cost-volume-profit (CVP) analysis extended  21


Decision making with VBA  21
If / Then / Else Decision structure  21
Creating a more complex CVP subroutine with decisions  24

9781488624872_FM.indd 5 6/25/18 10:56 AM


6
Costing, VBA Message and input Boxes Extended and Modularisation  27

Costing  27
Message boxes - extended  28
Input boxes - extended  30
Modularisation (break your overall model into subsidiary models)  32

7
Budgeting, Sensitivity Analysis & VBA loops  35

Budgeting 35
Sensitivity analysis  36
Do loops  36
For / Next loops  37
Count controlled loops  38

8
The Macro Recorder & Troubleshooting / Debugging  41

s
Overview of macros  41

ge
The macro recorder – basic use  41
Using the macro recorder to find VBA methods  44
Troubleshooting and debugging  44
pa
9
Statement of Financial Performance (Income Statement), Data ­Validation
& Filters / Validation & Reasonability Testing  47

The income statement  47


e
Validation & reasonability testing  48
Excel’s data import methods (VBA not required)  48
pl

Excel’s data validation methods (VBA not required)  49


Excel’s data filter capabilities (VBA not required)  51
m

10
Statement of Financial Performance (Balance Sheet), Logical functions
/ Presentation & Reporting / Documentation  55
Sa

The balance sheet  55


Logical functions – IF’s, nested IF’s, AND’s & OR’s   56
Demonstration of logical functions with the balance sheet  57
Presentation & reporting (tips for effective reporting of results)  58
The importance of documentation (may your model outlive you)  58

References 61

Appendix 62

Index 66

9781488624872_FM.indd 6 6/25/18 10:56 AM


1
Introduction

s
ge
OVERVIEW OF BOOK
The Excel spreadsheet provides you with an incredibly powerful and flexible means for perform-
ing calculations and analysing data. Our intention with this book is to introduce you to some of
pa
Excel’s more useful features that will assist you with various financial and management accounting
techniques. And to give you a taste of programming with Excel VBA.
We assume that you have a basic familiarity with Excel, e.g. that you can open & save an
Excel workbook file, enter data and create simple formulas. We further presume that you’re like
e
most Excel users and have no VBA (Visual Basic for Applications) skills. No VBA knowledge is
OK for many spreadsheeters. You can do an incredible amount of useful work with Excel without
pl

using Visual Basic. And this book will help you to expand your Excel skills. More importantly
though it will introduce you to the world of VBA and the virtually endless scope of capabilities
that it provides.
m

THE KEY TO PROGRAMMING AND THE CONCEPT OF ASSIGNMENT


Sa

The key to writing computer program code is to remember that while computers are incredibly
fast, they are not very smart. You must tell them exactly what to do, when to do it and how to do
it. Instructions must be extremely simple with no uncertainty. You cannot assume anything.
A critical first step in learning to program is understanding the language and vocabulary of
programmers. This is especially important when they use everyday words in a technical respect.
The terms “constants,” “variables,” and “assignment” have specific meanings in programming
beyond their meaning in general conversations. Your first task is to make sure that you understand
these terms and their ramifications for computer equations.
The basis for all computer languages (including Excel VBA) is that information is denoted
either directly as constants or symbolically as variables. Constants are values that stay the same (as
you might have guessed). In contrast, variables can take on different values. A constant (or more
correctly “the value of a constant”) can be assigned to a variable. However, a variable (or more
correctly “the value of a variable”) cannot be assigned to a constant.
Consider the following two VBA programs or subroutines. As for all VBA subroutines, they
begin with the word “Sub” followed by the subroutine name and “()”. The conclude with the words
“End Sub” and contain statements or instructions to be executed by the computer in order of

9781488624872_CH01-08.indd 1 6/28/18 5:50 PM


2  Chapter 1 Introduction

appearance. Each of the subs below uses the VBA message box function as a convenient way to
display the value of a variable.

s
ge
Sub CalcProfitA provides the calculation for profit as 30 and displays this value with its
final line of code. However, sub CalcProfitB has placed the profit calculation statement before
assigning a value to the variable Expense. This results in Profit being calculated with revenue of
pa
90 and null expenses resulting in a profit of 90. The assignment of 60 to Expense comes after the
Profit calculation and the program isn’t smart enough to realise it should be included. You knew
that Profit should have been 30 again but the CalcProfitB sub displays a profit of 90. It’s wrong
because your instructions weren’t clear.
It is useful to understand what the computer does when an assignment statement is executed.
e

Assignment is always right to left as shown below.


pl

Revenue = 90 is better shown as Revenue 90

The equals sign in the assignment statement can be thought of as meaning “is replaced by”
m

or “is assigned the result.” It is critical to recognize that this use is different from the conventional
mathematical meaning of equality.
A variable is the label that the computer associates with the memory location where it
Sa

stores a constant value. As shown below for the first three statements of sub CalcProfitA. The
first two statements (Revenue = 90 and Expense = 60) results in the VBA program creating two
storage locations in its memory, which it labels Revenue and Expense to which it stores the values
90 and 60. The third statement Profit = Revenue – Expense instructs the computer to subtract
the stored value of the variable Expense from the stored value of variable Revenue and assign the
result to the variable Profit.
Memory locations Program statements

Revenue
90 Revenue = 90

Expense
30 Expense = 30

Profit
Profit = Revenue - Expense
60

9781488624872_CH01-08.indd 2 6/28/18 5:50 PM


Chapter 1 Introduction  3

Assignment statements must always have a single variable on the left side of the equals sign.
Because they both violate this rule, the following legitimate algebraic equations would be invalid
as VBA statements:

a + b = c is not a valid VBA statement


3 = x – y + 99 is not a valid VBA statement

On the other hand, although the following statement is not a proper algebraic equation, it
is a perfectly valid assignment statement:

x = x + 1 is a valid VBA statement

After this statement was executed, the memory location for the variable x would have a value
that was one higher than its previous value.
Of course, computers also must process information other than numbers. For example,
they need to be able to handle names, labels, and identification numbers, which consist of letters,
numbers, and symbols. Such alphanumerical information is formally referred to as a string. In

s
VBA, string constants are enclosed in quotes. The variables in which they are stored are called
string variables. Here’s an example of the assignment of a string constant, “Wayne Gretzky”, to a

ge
string variable, n:

n = “Wayne Gretzky” pa
Executing this line of code causes a memory location called n to be set up containing the
string constant Wayne Gretzky.
e

Problems
pl

PROBLEM 1 Difficulty: Fundamental


m

Learning objective: Understand the concept of “assignment”


Write (on a piece of paper) computer statements/code to do the following:
Sa

a) Assign the number 532 to the variable x.


b) Assign the number 1679 to the variable y.
c) Assign a value to the variable Guess for your estimate of the sum of
these two numbers.
d) Add the two numbers and assign the result to the variable TheSum.
e) Let the variable Diff be the difference between your estimate of the
sum of the two numbers and the actual sum.

PROBLEM 2 Difficulty: Fundamental


Learning objectives: Understand the concept of “assignment”
Understand the idea of a “program”
Write (on a piece of paper) computer statements/code to calculate a Customer
Service Department’s weekly salary budget (SalaryBudget). This budget amount
is calculated as the number of department staff (StaffNumber) multiplied by the
standard weekly salary amount (WeeklySalary).
For the current budget calculation, assume that the department has 18 staff and
that the standard weekly salary is $1,000.

9781488624872_CH01-08.indd 3 6/28/18 5:50 PM


2
FSA and Basic Spreadsheet
Structure

s
ge
Financial statement analysis (FSA) provides an excellent means for illustrating the importance of
proper spreadsheet structure and the appropriate formula use.
pa
FINANCIAL STATEMENT ANALYSIS (FSA)
Financial ratios are simply mathematical computations that provide comparisons of various income
e
statement and balance sheet accounts. They offer an excellent way to scrutinize the financial
health of a business.
pl

The first step with FSA is to determine your target users. The target audience dictates which
key indicators and relationships require examination. Different users will have diverse goals which
will determine which ratios they find useful. Managers will tend to have a general interest in all
m

ratios, as they have an overall responsibility for both the short-term and the long-term performance
of the business. On the other hand, short-term lenders (e.g. suppliers) will primarily be interested
in the likelihood that they will be able to collect their account. As such, their main interest would
Sa

be with liquidity ratios.


Ratios are easy to calculate (particularly when you use a spreadsheet) and relatively easy to
interpret. The key with ratio calculation is consistency, e.g. the inclusion of prepaid expenses in
your quick ratio may be a matter for debate but whatever your decision, it should be consistently
applied. It is also critical to recognise that ratio analysis is only the beginning. FSA will serve to
highlight the financial strengths and weaknesses. Ratios do not explain why particular strengths
or weaknesses exist. Further investigation is required.

BASIC SPREADSHEET STRUCTURE (SEPARATE DATA SECTION)


Spreadsheet model development is like traditional programming in more than one respect. The
construction of spreadsheet formulas can be construed to be a type of programming.
Robertson (2000) provides the typical first step in the software development process as
being the recognition that all programs can be reduced to IPO - the programming acronym for …

• Inputs
• Processing (steps required to generate the desired outputs)
• Outputs
5

9781488624872_CH01-08.indd 5 6/28/18 5:51 PM


6  Chapter 2 FSA and Basic Spreadsheet Structure

While spreadsheet models are sometimes criticised by traditional programmers for com-
bining the processing and output components (and thus confusing matters), the IPO model is
still a useful starting point.
Good data is critical for all spreadsheet models. However, expert modelers concentrate
their efforts on the structure of their model, not with the search for and analysis of data. Novice
modelers will frequently spend a lot of time searching for and analysing data. Better or more
accurate data doesn’t necessarily mean that the model’s outputs will be better. It is essential to
remember that modeling is about forecasting the future. Data is past tense (i.e. history) which
may be useful for predicting future events but maybe not. The modeler should spend most of
their time developing an appropriate model structure (e.g. accurate and logical formulas). And
less time pursuing that elusive “perfect” data.

CELL REFERENCED FORMULAS (NO HARD CODING)


The hard coding of input data or constants into spreadsheet formulas is widely recognised as poor
model design. However, the importance of avoiding such design defect errors appears to be un-

s
derestimated as there is not an immediate error and there may never be one. The fact that many
models fail to apply this basic software design principle is almost certainly a major contributor to

ge
the incidence of spreadsheet errors and the lack of reusability of many models.
Powell and Baker (2004, page 97) provide an excellent explanation of why it is important to
isolate input data or parameters.
pa
“A common source of errors in spreadsheets is the tendency to bury parameters
in cell formulas and to replicate the same parameter in multiple cells. This makes
identifying parameters difficult, because they are not immediately visible. It’s
also difficult to know whether all numerical values of a parameter have been
changed each time an update is required. By contrast, the habit of using a single
e

and separate location considerably streamlines the building and debugging of


a spreadsheet.”
pl

The problem of hard coding of values into formulae has an equivalent in traditional pro-
m

gramming and VBA where a well-constructed program would rarely (never) enter a value
(a number) into a line of executable code. The recommended programming technique is to
assign the desired value to a named variable (e.g. RedFont = 3) and use this variable in the
Sa

program code. This can be contrasted to the inferior design that would simply type the value
3 into a line of code. The prevalence of such inferior design practices is caused by the practice
being quicker in the short run as the developer avoids having to create a variable and assign a
value to it. The resulting ‘magic number’ in the code makes programs more difficult to read,
understand, and maintain.

ENABLING MACROS
Excel’s macro security settings must be dealt with whenever your spreadsheet contains macros.
You will receive a SECURITY WARNING advising you to this regard on opening of the file.
Indicate your trust of the macro developer by choosing the option to Enable Content to allow
you to run the macros. You should not enable macros from unknown sources.

Developer tab not displayed


You may have some setup work to do on your PC before you can use Excel VBA. If the DEVEL-
OPER tab is displayed on the ribbon that’s great. Developer provides access to VBA. If you don’t

9781488624872_CH01-08.indd 6 6/28/18 5:51 PM


Chapter 2 FSA and Basic Spreadsheet Structure  7

see the Developer tab you need to select the FILE tab and then chose OPTIONS. Select the
CUSTOMISE RIBBON option and in the Main Tabs section (right side of the screen) “tick”
the box beside DEVELOPER. Select OK and you should be right. That is, your ribbon should
now display the Developer tab.

CHANGING MACRO SECURITY


Your macro security settings can be changed through the DEVELOPER tab. Select the MACRO
SECURITY option (yellow triangle with exclamation mark) from the left side of the ribbon. Select
the option to “disable all macros with notification”.

CREATING A FSA SPREADSHEET


The Excel spreadsheet file (Chapter2.xlsm) provides a financial statement analysis exercise that
illustrates the concept of maintaining a separate data section while requiring the input of cell

s
referenced ratio formulas to the output section of the spreadsheet. Exhibits 2a and 2b below
provide extracts from the Chapter2.xlsm spreadsheet file. Your task is to enter proper cell refer-

ge
enced spreadsheet formula for each of the current year ratios cells on Exhibit 2b. To assist you,
this worksheet provides answers for each of the ratios for the previous year and details of the
formulas to be used.
The Chapter2.xlsm spreadsheet provides the “Check my work” button that accesses VBA
pa
code to assess your assignment attempt. The self-assessment macro verifies the accuracy of your
formula by checking that your ratio formulas provide the correct value with a separate set of
­financial statement data. It does so by filling the ratio cells green if your formula is correct and
red if not. This is an example of the type of VBA code that you will learn how to create.
e
pl
m
Sa

Exhibit 2a.  Chapter2.xlsm financial statements (FS’s) worksheet - data section

9781488624872_CH01-08.indd 7 6/28/18 5:51 PM


8  Chapter 2 FSA and Basic Spreadsheet Structure

s
ge
pa
Exhibit 2b.  Financial statement ratios output section
e
pl
m
Sa

9781488624872_CH01-08.indd 8 6/28/18 5:51 PM

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy