Advanced Excel Data Analytics Manual
Advanced Excel Data Analytics Manual
DATA ANALYTICS
www.microsofttraining.net
TABLE OF CONTENTS
The OR Function...................................................................................................................................... 10
Excel displays the PivotChart and the Field List for you to begin choosing your fields and grouping
data......................................................................................................................................................... 40
In Excel, you can create meaningful names for cells or ranges that can be used to overcome these
difficulties.
The advantage of using names comes from the fact that a name, like Employees, is more meaningful and
less abstract than a reference like C2:C55. Also, named ranges are by default absolute, so if you copy or
AutoFill a formula using named ranges, it will maintain its original cell references.
Range names will make formulas much more readable and they will make it easier to find and reference
individual cells. When you are first designing your worksheet, you can create formulas using names
instead of traditional cell references, and then define the names for the corresponding ranges of data as
required. Basically, using range names in your worksheet improves clarity, improves organization, and
aids in the overall design.
In the New Name box, you will see the reference to the cell or range you selected in the bottom text
field. This is the reference that will be associated with the name you choose. To name your range, type a
name in the top text field and click OK. (If you wish, you can also add a comment to be associated with
your new named range.) The Scope refers to the parts of the workbook where your named range will be
valid.
Another way to name a cell or range is to select it, type the name in the name box on the formula bar,
and press Enter.
In this example, the cells B1 to B6 were selected and the name NewRange was entered into the name
box. (If you click the down pointing arrow just to the right of the name box, you will display a list of
range names used in the spreadsheet.)
Excel will not accept spaces between words in the names you choose. For example, “newrange” or
“newRange” would be acceptable, but “New Range” would not. Once you have defined your named
ranges, you can use them in formulas and functions just as you would a regular cell or range reference.
As an example, if you named a range of figures Sales, and you named another range of data Expenses,
you could calculate the total sales or total expenses by entering the function =SUM(sales) or
=SUM(expenses) respectively.
Using names for ranges and cells in this way makes your formulas and functions much clearer. When
you want to enter a range in a formula or function, it is much easier to remember and type the name of
the range, rather than specific cell references.
_ AND
_ OR
_ IF
_ NOT
_ FALSE
_ TRUE
_ IFERROR
These logical functions are important when doing advanced work in Excel because they can help you
control the behavior of your worksheets based on specific logical conditions.
This module will focus on the use of the logical functions IF, AND and OR.
The IF function
Excel’s IF function can often prove to be very useful. You can use this function to branch to different
values or actions depending on a specified condition. The structure of an If function is as follows: IF
(logical test, value if true, value if false)
IF functions are called conditional functions because the value that the function returns will depend on
whether or not a specific condition is satisfied. As an example, consider the following function: IF
(A1=10, 5, 1)
This function states that if cell A1 has a value of 10 the cell that contains the function will have the value
of 5. But if A1 doesn’t have a value of 10, the cell that contains the function will have a value of 1. In
other words, the function reads: if A1 equals 10 then return the number 5, else, return the number 1.
Let’s say that this next IF function is entered into cell B2: IF (A1<=100, A1*.5, C3*2)
This function states that if the contents of cell A1 is less than or equal to 100, the value in cell B2 will be
the value in A1 multiplied by .5; else, the value in B2 will be the value of cell C3 multiplied by 2.
You can insert an IF function by invoking the Insert Function dialogue and looking under the Logical
category, or by typing it directly into the formula bar.
The logic of the IF function can be a little confusing until you get used to it. The best way to get
comfortable with IF functions, is to practice using them.
You can also click the small fx button next to the formula bar to display the Insert Function box.
Clicking the Insert Function button activates the Insert Function dialogue box and provides access to the
large range of functions available in Excel.
• Select the function you wish to use from the available list and click OK or
• Type the name of the function you wish to use in the Search for a function area, press
Enter, select the function when it appears in the list and click OK.
When you do this in Excel 2010, a screen tip will appear with the possible functions that correspond with
the letters of the function name you have entered.
For example, if you type =IF into a cell the following appears.
If there is more than one function listed, you can toggle between them by using the arrow up or arrow
down keys.
Once you have selected the function you wish to use, continue by typing in a left bracket, which will
cause the function syntax to display in another screen tip.
Continue to enter all the arguments required for the function to give you a result, ensuring you type a
comma between each argument.
Notice that the arguments joined by AND are placed in parenthesis and separated by commas. The
Excel function =AND(1<10, 2>1) means the exact same thing as saying 1<10 AND 2>1 in plain English.
Because 1 is less than 10 and 2 is greater than 1, the Excel AND function returns the logical value True.
You can have as many as 255 logical arguments to an Excel AND function. You can enter these
arguments directly, or use cell references as the situation requires. (All of the arguments should be
separated by commas.)
The following table (often referred to as a truth table) may help you understand the AND function. In
the last column of the truth table, you will see the value returned by the function, according to the
corresponding values of the function arguments.
A B AND (a, b)
The OR Function
The logical OR function will return true if one or more of the arguments to the function are true. For
instance, the compound statement 1<10 OR 2<1 is true, since 1 is less than 10. It does not matter that
the statement 2<1 is false, because you have a choice of either 1<10 OR 2<1 to make the compound
statement true. If one or both of the arguments is true, the overall OR statement will also be true.
If one or more of the function arguments is true, the OR function will return true.
Notice the function and its comma separated arguments in the formula bar.
A B OR (a, b)
=AVERAGE(SUM(B2:B6),SUM(C2:C6),SUM(AVERAGE(B2:B6),AVERAGE(C2:C6),AVERAGE(D2:D6)))
Notice that this function has 3 average functions nested within a sum function, which is in turn nested in
another average function. This may seem confusing, but if you carefully step through the function from
right to left, it becomes clear.
The average of range D2:D6, the average of C2:C6, and the average of B2:B6, are summed together. This
sum is then averaged with the sum of C2:C6 and the sum of B2:B6 for a final result.
In terms of nested functions, nesting averages within sums and sums within averages is probably not
that practical; however, nested IF functions can be extremely useful for a wide variety of situations.
Nested IF functions
The IF function is ideal for making choices based on logical tests. Furthermore, you can nest IF functions
one inside another.
=IF(A1=10,100,IF(A1=5,200,0))
In the case of this IF function, if the value in cell A1 is 10 the function will return 100. If the value in A1 is
not 10, the function will test if the value in A1 is 5. If the value in A1 is 5, the function will return 200. If it
is not 5 (and also not 100) the function will return 0.
When you nest logical functions, you must make sure that the number of closing parenthesis matches
the number of opening parenthesis used in the function. If you count the parenthesis in the function
from the image above, you will see two opening, and two closing parenthesis.
Applying Logical Functions
The spreadsheet in the image shown above is used to calculate the future budget increase for different
divisions of a fictional company. If you look carefully, you will notice that the Miami division has had its
budget increased from 1,500,000 to 1,800,000. Also, the Chicago division has had its budget increased
from 2,000,000 to 2,400,000. The question that arises here is, “What reasoning was used to arrive at
these budget increases for these particular cities?
For the answer to this question, look at the formula bar when a cell from the Future Budget Increase for
Division column is made active.
When cell F2 is the active cell, you can see the formula from cell F2 in the formula bar.
=IF(OR(C2-D2>500000,AND(C2>D2,E2>20%)),B2*1.2,B2)
To understand this formula as a whole, you must first understand how each logical function is used in
the formula. To start, remember that the IF function will return a certain value based on a logical test.
OR(C2-D2>500000,AND(C2>D2,E2>20%))
The OR function will return true if one or more of its arguments are true. The first argument in the OR
function is C2-D2>500000. This is a simple argument that will return true when the value of cell D2
subtracted from cell C2 is greater than 500,000.
The second argument AND(C2>D2,E2>20%) is a logical AND function. This function will return true only
when both of its arguments are true. That is, the AND function will return true only when the value in C2
is greater than the value in D2, and the value in E2 is grater than 20%.
If the first argument to the OR function is false, the AND function must return true for the OR function
to be true. Alternatively, if the AND function returns false, the first argument to the OR function must
return true for the OR function itself to return true.
If we use the column headings instead of specific cell references, the logic of this OR statement reads:
When the OR function (the logical test for the IF function) returns true, the IF function will give the value
B2*1.2 (the original budget increased by 20 percent).
When the OR function returns false, the IF function will give the value B2 (the original budget value).
If you wanted to summarize the formula shown in the formula bar in plain English, you could say the
following:
Logical functions can be difficult to grasp at first, especially if they are nested into a larger formula. If
you are confused by a formula involving one or more logical functions, take your time and carefully
study the function arguments. Study one function at a time until you understand the logic, test
conditions, and the value or values that the function will return. If you understand each individual
function in a formula, pretty soon the entire formula will make sense to you.
Module Two: Working with Lookups
This module introduces the use of the VLOOKUP and HLOOKUP function.
Excel 2010 provides two lookup functions that you can use to quickly retrieve information from a table.
The functions are called HLOOKUP (horizontal lookup) and VLOOKUP (vertical lookup).
The VLOOKUP function will look in the leftmost column of a table for a value you specify. When it finds
the value you specified, it will return a value that is located in the same row, a specified number of
columns into the table. It is called VLOOKUP because it looks vertically down a column for a match, and
then retrieves data from across the row.
HLOOKUP is similar, but it will look horizontally across the upper row of your table, and then retrieve
data from down a column.
If we activate a cell F1 and enter =VLOOKUP("England",Price,2) into the formula bar, cell F1 will show
the value 550.
The lookup function looked vertically down the leftmost column of the lookup table (Price) until it found
a match for the text string “England.” The function then returned the value that is in the second (2)
column of the table, from the row where the match was found. You should notice that England, Price,
and 2 are the exact arguments used in the function.
The arguments for the lookup function are: VLOOKUP(value to match, lookup table name or range,
number of the column in the table containing the relevant data, true or false).
For the example shown above, the true or false argument was left out. The relevance of the true or false
argument in the VLOOKUP function will be discussed shortly.
HLOOKUP is the same as VLOOKUP, except that it looks across rows for a match rather than down
columns. To use HLOOKUP, the lookup table would be arranged in this way.
Since Excel is designed with more cells in the vertical direction than in the horizontal direction, and
because vertical table design is more intuitive for most people, VLOOKUP is generally used more often
than HLOOKUP.
To use the VLOOKUP function correctly, you need to have your spreadsheet data laid out properly in a
table with at least two columns. The first column in the table will contain the keys (identifiers that the
VLOOKUP function will look through for a match). In the example just shown, the keys (or identifiers) are
the names of the countries. This first column can be referred to as the look up column.
The other columns in your table will contain data that is associated with the column of identifiers. Your
table can be several columns wide, and you can specify which column VLOOKUP will return data from by
putting a number corresponding to the given column in the function. In the previous example, we
wanted VLOOKUP to return the ticket price, so we used the number 2 (for the second column) as an
argument in the function.
If your table has 10 columns and you want to return data from the ninth column, you would use 9 as an
argument.
You do not have to use text values (like the country names used here) in your lookup column. If it is
more appropriate, you can use numbers or dates. If you want some help when you are using VLOOKUP,
use the Insert Function dialogue by clicking the fx button next to the formula bar.
You will find the VLOOKUP function in the Lookup & Reference category. If you click the OK button in the
Insert Function dialogue, you will see the helpful Function Arguments box.
Here, you can enter the function arguments in the fields provided by following the instructions and
descriptions that correspond to the given fields.
How to Find an Exact Match with VLOOKUP
As mentioned briefly before, the VLOOKUP function can take a final argument of either true or false. If
you specify this final argument as false, VLOOKUP will search for an exact match in the lookup column
(column of identifiers). If it cannot find an exact match, no data will be returned.
In the following example, the function =VLOOKUP("jpn",Price,2,FALSE) has been entered in cell D1. This
means that VLOOKUP will search the first column of the table for an exact match of “jpn,” and if it is
found, it will return the corresponding value in column 2.
Because there is no country that exactly matches “jpn” no value will be returned to cell D1.
If you change the function so that the first argument is “Japan,” an exact match will be found and the
value 925 will be returned to cell D1. If there are two or more exact matches, the first matching value
found in the column of identifiers will be returned.
The VLOOKUP function’s exact match is not case sensitive, so jaPan is considered an exact match of
Japan. You can also use wild card characters so that Ja?an and J* will match Japan as well.
Finding the Closest Match with VLOOKUP
If the final argument in your VLOOKUP function is true, VLOOKUP will search the column of identifiers
for the closest match to the search value you enter as the first function argument.
For example, in you enter a search value, and you enter true as your final argument, a value associated
with the first exact match of your search value will be returned (if one is found).
However, if no exact match is found, a value corresponding to what Excel deems is the closest match will
be returned.
Following our example, if you enter “jpn” as the search value for the table of ticket prices, the value
associated with the country Japan (925) will be returned, as Japan is the closest match to jpn that is
found in the look up column.
If you omit the final argument in your VLOOKUP function, it will default to true, and search for a closest
value if it cannot find an exact match.
If you are using the True argument, the values in the look up column should be sorted in ascending
order. Otherwise, you may get unexpected results. If you are using text values in your lookup column,
avoid using leading or trailing spaces, as this also may produce unexpected results. However, if you use
'False' (for an exact match) as the final argument in your function, the lookup column does not have to
be sorted.
Module Three: Advanced List Management
This module will explore applying data validation settings to your worksheet to control data entry. You
will also identify and use database functions to perform calculations using multiple database fields.
1. Select the cells where you want to apply the data validation rule.
2. Select the Data tab from the Ribbon.
3. Select Data Validation. Select Data Validation.
4. On the Settings tab of the Data Validation dialog box, set up the Validation Criteria. Use the
drop down lists to help you build your criteria. In this example, we are requiring a three-digit
number.
If you select the Settings tab and choose List from the Allow drop menu, you will see a data box (labeled
Source) where you can enter permissible source data for the cell.
You can type the values that are permissible for the cell directly, or specify a range that contains the
values.
If you specify a cell range, make sure there is an equals sign = in front of it.
In this image, cell E2 is being set up so that items in cells A2 to A9 (surrounded by a dashed border) will
be available as choices for data entry.
Now, a user can choose from a validation drop list that is available for cell E2.
This means that if the value entered into cell G4 (the cell that is being validated) is not 100, the function
will return TRUE. If it is 100 the function will return FALSE. If the validation formula returns true, the
data is permitted. If FALSE, the data is invalid. Basically, this formula allows any number other than 100
to be entered.
There are many possibilities for setting data validation rules. For example, you can select a range of
cells, click within the range, and click the Data Validation button on the Data Ribbon to set up validation
rules for the entire range. You can also AutoFill a cell with validation rules into other cells in a row or
column. These cells will all have the same validation properties.
With database functions you can get counts, averages, or sums of your database on selection criteria
involving multiple fields. Implementing database functions is a little like implementing advanced filters:
you have to establish a criteria range first before you use the function itself.
We will use the DSUM database function to calculate the total profit for all Tuesdays and Thursdays with
Sales greater than 2200 and Profit less than 1900.
If you wanted to join the criteria with a logical Or operator, you would offset the criteria on separate
rows (like an advanced filter).
First, select your original list with your mouse, or enter the range directly into the Database data area.
Press Tab or use your mouse to move to the Field data area and type Profit (this is the field that will be
summed).
Then, put your cursor in the Criteria data area, and select the entire criteria range (F1:H2) with your
mouse. To finish, click the OK button.
You can see the sum of the Profit fields for records that meet the criteria in cell H4.
You could have also activated cell H4, and entered the function directly into the formula bar:
=DSUM(A1:D25,"Profit",F1:H2)
If you enter a database function directly into the formula bar, remember to keep your cell ranges
accurate, and put the field that will be summed, averaged, or otherwise operated on, in quotation
marks.
Module Four: Creating Pivot Tables
PivotTables allow you to analyse numeric data in depth. You can use this tool to answer unanticipated
questions about data. PivotTables are interactive, cross-tabulated Excel reports that summarize and
analyze data. In this module, you’ll learn how to insert a chart. You’ll gain an understanding of the
PivotTable Tools tab. You’ll also learn how to choose fields for your table and group data.
What is a PivotTable
A PivotTable is a powerful tool for exploring and analyzing information. A PivotTable helps you organize
and manipulate the raw data in your spreadsheet, giving you insight into patterns or relationships that
might not be obvious at first glance. PivotTables also give you the power to view your data in a different
context without changing the original content or structure.
You can base a PivotTable on data in your current workbook or even external data from another source
if you wish. With a PivotTable, you can conveniently drag and drop columns of your data to different
areas of the table to examine relationships or trends that may not be obvious in a traditional Excel table
or database.
You could build several separate tables to explore how columns from an Excel worksheet relate to each
other, or you can use one PivotTable to do the same thing. With a PivotTable, you can alter the table
design without cutting, copying, pasting, or adjusting formulas and cell references. (These tasks can be
frustrating when dealing with a large volume of data.)
In short, PivotTables enable you to organize your data in meaningful ways without doing a lot of tedious
work. You could say that a PivotTable is like several data tables rolled into one.
The following image shows a block of contiguous data that is well suited for a PivotTable.
Notice that there are no empty rows or columns and that every column of data has a unique label.
Creating a PivotTable
To create an Excel 2010 PivotTable, just select the range of data that you want to base the table on and
then click the PivotTable button on the Insert Ribbon to display the PivotTable dialogue.
If you choose the External Data Source option, you can base your PivotTable on data outside your
current workbook (such as another workbook or perhaps an external database). If you select the Use an
External Data Source radio button, you will be able to display a drop list of existing connections in the
Connection Name field. A typical existing connection could be a Microsoft Query or a connection you
previously made to an Access database for some other purpose. Excel displays the PivotTable and the
Field List for you to begin choosing your fields and grouping data (discussed in the next topic).
Choosing Fields and Grouping Data
When you add a PivotTable or PivotChart to your worksheet, the table or chart is blank at first. You must
choose the fields you want to display on the chart. The PivotTable Field List pane makes it easy to select
the fields you want on the chart.
1. Check the box next to a field listed in the PivotTable Field list to include it in the report. The
default location where fields are added are as follows:
• Nonnumeric fields are added to the Row Labels.
• Numerical fields are added to the Values area.
• Date and time values are added to the Column Labels.
The bottom of the PivotTable Field List pane includes four areas:
• Report Filter
• Axis Fields (categories or row labels)
• Legend Fields (column labels)
• Values
1. Right click on a field label in the PivotTable Field List and select one of the options from the
context menu.
2. You can also simply drag the fields from one area to another. You can even drag a field from the
top portion of the pane to one of the bottom areas.
Use the following procedure to refresh the PivotTable after making a change to the data.
Excel returns to the worksheet of the source data and highlights the current data source. It also displays
the Change PivotTable Data Source dialog box.
4. Excel automatically provides a range of cells based on your selection. You can change the table
or range if desired.
5. Select a location for the PivotChart. You can have Excel create a new worksheet or select one of
the existing sheets.
6. Select OK.
Excel displays the PivotChart and the Field List for you to begin choosing your fields and grouping data.
7. Add fields to view the chart.
If you create a PivotTable that includes the Salesperson and the Order Amount, you get this.
Select the arrow next to the Count of Order field in the Value area and select Value Field Settings from
the menu.
Click the arrow next to Row labels and select More Sort Options.
In the Sort dialog box, select Ascending (A to Z) by Sum of Order Amount and select OK.
Module Five: Using What If Analysis
“What-if” analysis allows you to have Excel change the values in cells so that you can see how those
changes affect the formulas outcomes. There are three kinds of what if analysis: goal seek, scenarios,
and data tables. Goal seek allows you to find the necessary value for an unknown in a formula to obtain
desired results. Scenarios allow you to view multiple different possible results for up to 32 variables.
Data tables allow you to quickly calculate multiple results for one or two variables in one operation. You
can view and compare the results of all the different variations together on your worksheet. This
module introduces these tools.
1. When using goal seek, one value from a formula should be left blank.
2. Select the Data tab from the Ribbon.
3. Select What If Analysis. Select Goal Seek.
4. In the Set Cell field, enter or select from the worksheet the cell that contains the formula. In the
sample file, select $B$4.
5. In the To Value field, enter the formula result you want. For example, in the sample file, you
may want the resulting payment of $900. You would enter -900 because it is a payment.
6. In the By Changing Cell field, enter or select the reference for the cell that contains the value
you don’t know. In the sample file, this is $B$3.
7. Select OK.
Excel displays the Goal Seek Status dialog box. Select OK to close it.
You may need to reformat the cell with the new answer to view the answer in the preferred format.
First you create a scenario for each different value. You can double-click the scenarios in the Scenario
Manager to see the different results of each scenario. Then you create a summary to view a report
containing the results.
10. Select Add to create another set of values. If you have finished adding all the possibilities, select
OK to return to the Scenario Manager.
11. Repeat steps 4 through 10 to create another scenario.
12. On the Scenario Manager dialog box, you can double click a scenario name to see the results. To
view a report, select Summary.
When you use a data table, Excel will substitute a range of values into the worksheet formulas for you
and tabulate the results so they can be viewed easily.
In Excel, you can create a single input data table or a two input data table. A single input table will
substitute a range of values as a single variable in as many formulas as you like. With a two input data
table, you can specify ranges for two input variables, but these input variables can only be applied to
one formula.
An example could be, Currently, the firm has 10 clients. The values for wages, total client costs, total
expenses, and profit are all calculated by formulas dependent on the number of clients the firm can
retain.
To see what results the profit formula and other formulas would produce for a range of hypothetical
client numbers, we can use a single input data table.
First, list the values that you want to input into the formulas in a row or column of adjacent cells. For
this example, a column of input values is used. In the row just above your input column, enter cell
references to the formulas that you want to evaluate.
Make sure you enter the references starting one cell to the right of the column of input values.
In the example spreadsheet that follows, the input variables are in the cell range E5:E30. Cell F4 contains
the reference =C5, cell G4 contains the reference =C13, and cell H4 contains the reference =C15, for the
total income, total expenses, and total profit formulas respectively.
It is a good idea to label your columns appropriately, so you can clearly understand the data table
results. In this example, the same labels that appear in the source data are used for the single input data
table.
Notice that the formula references (F4:H4) are in a row just above and one cell to the right of the first
input variable (E5). The data table is now ready. The input variables are listed in the Clients column and
the formula references are one row above and one cell to the right. All of the elements in the data table
are clearly identified.
Creating a One Input Data Table
The next step is to select the range of cells from the data table containing the input variables and the
formula references. In this example, the range is E4:H30.
Next, choose the Data Table option from the What-If Analysis button to display the Data Table dialogue
box.
The range of input variables and formula references has been selected, and the Data Table dialogue box
is ready for input.
Because the input variables are arranged in a column, we will use the “Column input cell” text field in
the table dialogue box rather than the Row input cell field. In the “Column input cell” text field, enter
C3, which is the cell from original data area that contains the number of clients.
(Remember that the number of clients is also our chosen input variable.)
Clicking the OK button in the Table dialogue box will complete the data table.
You can now see at a glance how the 26 different values in the Clients column influence the income,
total expenses, and total profit results.
If you change the values in the Client column, the data table will recalculate in accordance with the new
values automatically. You can apply formatting styles, borders, shading, and other enhancements to the
data table in the same way as you would any other area of your worksheet.
Creating a Two Input Data Table
If you want to examine the effects of two input variables on a single formula, you can use a two input
data table.
To build a two-input data table, first choose an empty cell and enter a reference to the formula you
want to examine. Using the same consulting firm example as before, we will choose cell E2 and enter
the reference =C15 for the Profit formula.
The next step is to create two variable ranges. One range will be a column starting in the cell
immediately beneath the formula cell and the other range will be a row starting on the immediate right
of the formula cell. This means that the formula cell (E2) will be at the upper left corner of the two input
data table.
For the column of input variables, we will again use the number of clients. For the row of input variables,
we will use the Fee Per Client. (The formula for the Profit values is indirectly dependant on both of these
variables.)
After entering some hypothetical values for the number of clients in cells E3:E15 and some different
client fee values in cells F2:J2, we will end up with a worksheet something like this:
Shading, labels, and currency formatting have been added to the data table for clarity.
The next step is to invoke the Data Table dialogue – select Data ribbon, Data Tools group, click the
What-If Analysis button and select Data Table. . This time, the formula referenced in E2 will be evaluated
once for every combination of Clients and Client fees, that exists in the table.
First we will select the range of data cells E2:J14 and then we will choose the Data Table option from the
What If Analysis button.
This time, we have two input variables: one corresponding to the row of Client fees and one
corresponding to the column containing the Clients data.
In the Row Input Cell text area type C4, because the row of client fees corresponds to cell C4 in the
original data. Similarly, in the Column Input Cell, type C3. The Data table dialogue box should look like
this.
What is a macro?
A macro can be described as a tiny program that uses Visual Basic code to automate a sequence of
actions or instructions.
A macro can be simple and consist of only a few tasks or commands, or be quite complex, involving lots
of data manipulation and calculations. To create complex macros, it is worthwhile to invest time in
learning Visual Basic programming. But for simple macros, you don’t have to do any programming at all.
Simple macros are great for any long sequence of keystrokes that you find yourself repeating often, or
for combinations of basic Excel actions that would be convenient to automate for a particular workbook.
Macros can be saved with the workbook in which they were created, or they can be saved in a separate
personal macro workbook where they are more accessible.
Displaying the Developer Tab
The Developer tab is where the tools involving macros are located. The Developer tab is not displayed by
default, so you’ll need to let Excel know that you want to work with it. You use the Options dialog box to
display the Developer tab.
Developer tab
Recording and Running Macros
A macro is recorder that you turn on, perform a series of actions that you’ll need to perform repeatedly,
and then turn off. Excel stores the recording and makes it accessible to any Excel worksheet. You can
record any menu action or command to make it part of the macro.
To record a macro, you turn on the recorder, perform the actions you want to record. Then you turn off
the recorder.
Use the following procedure to record a macro. In this example, we will sum the column and add
formatting to the numbers.
5. To make the macro available to other worksheets, select Personal Macro Workbook from the
Store Macro In drop down list.
6. Select OK to begin recording.
7. Perform the actions you want to record. In this example, we inserted a Sum and then formatted
the total with a currency formatting and added bold face formatting.
8. Select the Developer tab.
9. Select Stop Recording.
1. Place your cursor in the cell where you want to perform the macro.
2. Select the Developer tab.
3. Select Macros.
4. In the Macro dialog box, select your macro name from the list.
5. Select Run.
Note that when you close Excel, you will get the following warning message.
Select Save to keep the macro and make it available to other workbooks.
Changing the Security Level
Excel security may prevent some of your macros from working, depending on where the workbooks
containing the macros are located. You can change the security settings to avoid warning messages each
time your run certain macros.
To digitally sign a macro, click the Developer tab to display the Developer Ribbon and then click the
Visual Basic button to launch the Visual Basic Editor.
In the tool bar at the top of the Visual Basic Editor’s window, click the Project Explorer button.
In the navigation panel on the left of the editor window, highlight the VBA Project/Worksheet
containing the macro you want to sign, and then click the Digital Signature option from the Visual Basic
Editor’s Tools menu.
If you specify relative cell referencing for a macro, the actions performed by the macro will be relative to
the active cell when you start the macro. This means that the macro can perform actions on different
cells each time it is run, depending on what cell is used as the starting point.
To record a relative reference macro, choose your active cell and click the Use Relative References
button before you begin recording.
Once you click this button, simply click the Record Macro button as before to create the actual macro.
When you stop the macro recording process, all of the cells that were involved in the macro will be
treated as having relative references.
Let’s say, for example, that the active cell is B1 and you create a relative reference macro that shades
the cell C1 in blue. If you make cell K10 the active cell and run the macro, cell L10 will be shaded in blue.
If this were an absolute reference macro, cell C1 will become shaded in blue no matter what the active
cell is when you run the macro.
Running a Relative Reference Macro
To run a relative reference macro, first make sure that the active cell is chosen such that the cells that
you want the macro to run on are in the correct relative position.
As an example, suppose that you created your relative reference macro with A1 as the active cell. The
macro that you created changes the column of six cells immediately below A1 (A2:A7) to accounting
format.
Now, if you wanted to convert cells H3:H8 to accounting format, first pick cell H2, which is in
the same relative position to H3:H8 as cell A1 was to A2:A7.
Now, click the Macro button and choose the correct macro from the Macro dialogue box.
First, you must use Excel to open the template or workbook containing the macro, as well as the
workbook that you are copying the macro into. When both workbooks are open, select the Developer
tab on the destination workbook and click the Visual Basic button to display the Visual Basic Editor.
When the Visual Basic Editor opens, you will see all of the currently open workbooks in the
Project Explorer panel on the right.
(If you cannot see the Project Explorer panel, click the Project Explorer button in the Visual Basic Editor
Toolbar.)
When you record a macro for a workbook, it will be contained in a code module shown in the Visual
Basic Editor. In the image shown above you can see that Book3 (the destination workbook) has no
modules, but the other open workbooks and templates (macTemplate.xltm and sourcebook.xlsm) have
module folders with them.
To copy a macro from a template or a workbook, open the module folder for the workbook or template
that you want to copy from by clicking on the plus (+) sign corresponding to the folder.
In the following image, the modules folder for macTemplate.xltm has been opened.
To copy the macro from macTemplate.xltm to Book3, just select and drag Module1 from the open
Modules folder up to the Book3 area (drag until you see your mouse pointer turn to a plus (+).
Now, both Book3 and macTemplate.xltm have code modules associated with them.
If you double click on the Module1 icon under Book3 and double click on the Module1 icon under
macTemplate.xltm, you will see code windows for both modules (and the macros contained in the
modules) open in the editor.
If you examine the VBA code for both modules (macros) in the editor window, you will see that they are
identical.
If you save Book3 as a macro enabled workbook, the process of copying the macro will be complete!
Customizing and Changing the Quick Access Toolbar
Use the following procedure to add a macro to the Quick Access Toolbar.