Anda di halaman 1dari 109

2010

TABLE of CONTENT
PART ONE: THE EXCEL ENVIRONMENT
INTRODUCTION.......................................................................................................................... 5
What Is Excel? ............................................................................................................................ 6
Rows, Columns, Cells, Range Of Cells ......................................................................................... 7
Worksheet, Sheet Tab, Workbook ............................................................................................. 8
Ribbons, Quick Access Toolbar (QAT), & File Backstage View .................................................. 10
Excel Names -- Named Ranges ................................................................................................. 13
Remove Duplicates .................................................................................................................. 16
Data Validation ........................................................................................................................ 18
Relative, Absolute AND Mixed Cell Reference.......................................................................... 21
PART TWO: CALCULATING WITH EXCEL
Create Basic Formulas .............................................................................................................. 24
Calculate with Functions .......................................................................................................... 25
SUM FUNCTIONS ..................................................................................................................... 26
Count Functions ....................................................................................................................... 33
IF FUNCTION ............................................................................................................................ 41
VLOOKUP FUNCTION ............................................................................................................... 46
SEARCH FUNCTION .................................................................................................................. 50
INDEX FUNCTION ..................................................................................................................... 54
MATCH FUNCTION ................................................................................................................... 60
INDIRECT FUNCTION ................................................................................................................ 63

PART THREE: DATA ANALYSIS


How to Set up Your Data for Easy Sorting and Subtotals .......................................................... 71
How to Sort Data ..................................................................................................................... 73
Add Subtotals to a Data set...................................................................................................... 79
Use a Pivot Table to Summarize Detailed Data ........................................................................ 84

PART FOUR: STREAMLINING WORKFLOW


Apply Conditional Formatting .................................................................................................. 90
Advanced Filter Apply an Excel Advanced Filter ....................................................................... 96
Record and Test Macro .......................................................................................................... 104

INTRODUCTION
Excel is Fun! Why? Because youre efficient use of Excel can turn a three hour payroll calculating chore or a
five hour reporting task into a five minute breeze. Efficient use of Excel will save a lot of time. That time
adds up to extra time for your more enjoyable endeavors in life such as vacations! In addition, your bosses
and employees will notice that you are efficient and can produce professional looking reports that impress.
This of course leads to promotion more quickly. Still, further, your knowledgeable and efficient use of Excel
can land you a job during an interview. Employers are like dry sponges ready to soak up any job candidate
that can make their entity more efficient with Excel skills! Save time? Get promoted? Get the job? And
have more time for vacation? That sounds like a great skill to have!
In the working world, almost everyone is required to use Excel. Amongst the people who are required to
use it, very few know how to use it well; and even amongst the people who know it well, very few of those
people know how to use it efficiently to the point where grace and beauty can be seen in a simple
spreadsheet!
This book will take you from the very beginning basics of Excel and then straight into a simple set of
efficiency rules that will lead you towards Excel excellence.

What Is Excel?
You use Word to create letters, flyers, books and mail merges. You use PowerPoint to create visual, audio
and text presentations. You use Google to research a topic and find the local pizza restaurant. You use
Excel to make Calculations, Analyze Data and Create Charts. Although databases (such as Access) are the
proper place to store data and create routine calculating queries, many people around the planet earth use
Excel to complete these tasks. Excels row and column format and ready ability to store data and make
calculations make it easy to use when compared to a database program. However, Excels essential beauty
is that you can make calculations and analyze/manipulate data quickly and easily on the fly! This easy to
use, planet-earth default program must be learned if you want to succeed in todays working world.
Open up the Excel file named LearningEXCEL 2010.xlsx and with your mouse, click on the What is Excel
sheet tab.
Here is an example of how Excel can make payroll Calculations quickly and with fewer errors than doing it
by hand.

Sheet tab What is


Excel?

Rows, Columns, Cells, Range Of Cells


With your mouse, click on the Rows and Columns sheet tab.

Name Box

Sheet tab
Rows and
Columns

Rows are horizontal and are represented by numbers. In our example the color blue has been added to
show row 5.
Columns are vertical and represented by letters. In our example the color yellow has been added to show
Column B.
A cell is an intersection of a row and a column. In our example the color green has been added to show cell
B5. In our example column B and row 5 can be detected because the column and row headers are
highlighted in a light-orange color (Figure 4)(color may vary by computer). In addition, you can see that the
name box shows that cell B5 is selected (Figure 4and Figure 5).

B5 is the name of this cell. It can be thought of as the address for this cell. It is like the intersection of two
streets. If we wanted to hang out at the corner of Column B Street and Row 5 Street, we would be hanging
out at the cell address B5.
Later when we make calculations in Excel (making formulas), B5 will be called a cell reference.

A range of cells is two or more cells that are adjacent. For example you
can see three blue cells D9, E9, and F9. This range would properly be
expressed as D9:F9, where the colon means from cell D9 all the way to cell F9.

Worksheet, Sheet Tab, Workbook


A worksheet is all the cells (1,048,576 rows, 16,384 columns worth of cells). A worksheet is commonly
referred to as sheet.
The sheet tab is the name of the sheet. By default they are listed as Sheet1, Sheet2. In our example, the
sheet we are viewing is named Rows and Columns. You can see other worksheets that have been given
names in our example. Can you see what they are?
Naming your sheets helps you to keep track of things in a methodical way. Navigating through a workbook,
understanding formulas and creating headers/footers is greatly enhanced when you name sheets. To name
your sheet, 1) double-click the sheet tab (this highlights the sheet tab name), 2) type a logical name that
describes the purpose of the sheet, and 3) hit Enter. You can also, right-click a sheet tab and point to
rename in order to give the sheet a new name.

A workbook is all the sheets (over 8000 worksheets possible limited my


computers memory). To name a new workbook that has not
been saved or named, use Save As (Keyboard Shortcut = F12).
The Save As dialog box (depending on your operating system, this
may look different):
File path (top red circle) = Where do you want to save it?
File name = what do you want to call it?
Save as type = What type of file is it?(.xlsm? or .xlsx or .xls or .htm? or .xltm or .xlt?)
See notes on next page about the new Excel 2007/2010 Save as types.
Some of the Excel 2007/2010 Save as type or extension type or file format:
1. xlsm
i.

2007/2010 workbook that allows Macros (Macros = custom code that you can put in
workbook (VBA))
ii. This file format is called XML (Extensible Markup Language). XML is efficient because:
1. Most any program can read it
2. It is less corruptible
i. Lose a few lines in BIFF and you can lose the whole file, lose a few lines in
XML and you can easily recover the file
iii. This new file format is different than XML in 2003 (2003 XML did not support VBA,
Charts, and other embedded images), it now supports all Excel elements.
iv. These files are actually zipped files!!!!
i. Saves space

2. xlsx
i.

This is the same as the description for .xlsm except that does not allow Macros (Macros
= custom code that you can put in workbook(VBA))

i.

1997 2003 file format


1. Use this if you are going to let other people use your file that do not have Excel
2007/2010

3. .xls

4. .htm
i. Saves worksheet or workbook as html (web site)
5. .xltm
i. 2007/2010 Excel Template that allows Macros
1. Templates automatically save to the Microsoft Template folder so that your
template will show up in the Templates window
6. .xlt
i. 1997 2003 file format for Templates

7. .xlsb
i.

This file type is called BIFF (Binary Interchange File Format)


1. BIFF5 (Excel 95)
1. BIFF8 (Excel 97-2003)
2. BIFF12 .xlsb
i. BIFF cannot be read by many applications
ii. But it saves and loads more quickly than XML

Save As is different than Save


Once you have saved your workbook for the first time, subsequent saves will replace the stored file with
the most recent changes. Save as gives you the power to:
1) Save the file to a new location
2) Save file with a new name
3) Change the file type. In this way the Save As dialog box is very powerful.

Ribbons, Quick Access Toolbar (QAT), & File Backstage View


The menus and toolbars from earlier versions of Excel (prior to Excel 2003) are gone. In their place are
Ribbons, the Quick Access Toolbar (QAT) and the File Backstage View. The Ribbon contains tabs(such
as Home, Insert, etc.) and each tab contains icons and words that let you click on a particular icon to take a
particular action such as changing the font size or changing the number of decimals showing for a number.
The icons and words are grouped into categories to help the user find similar items. These categories are
called Groups. To select a Ribbon tab, click on the tab with your mouse. You can only view one Ribbon at
a time. showspart of the Home Ribbon tab. The Ribbons change appearance depending on the size of your
screen and/or your computers screen resolution (screen resolution can be changed in Display Properties
in Windows 7, you can right-click the desktop and point to Screen resolution).

Figure 1

File tab

QAT

Examples of Groups on
the Home Ribbon

Examples of icon
buttons

The File tab is located in the upper left corner of the screen, to the left of the Home Ribbon tab. If you click
on it opens the backstage view. On the next page shows the File Backstage View and shows that this
10

allows you to access things such as Print, Save As and Recent. On the
next page shows the amazing recent option that allows you to open
recently accessed files and folders. THE MOST IMPORTANT thing to know about the backstage view is that
when you want to close this view DO NOT USE THE x IN THE UPPER RIGHT CORNER. To close use the
Exit button in the lower left or simply use the Esc key.
The Quick Access Toolbar (QAT) contains the icons for save, undo and redo by default and then any other
additional icons that you add yourself. There is only one QAT. The QAT is always visible and available for
use, either above the Ribbons or below the Ribbons depending on where you place it (right-click QAT to
move it). We will see how to customize the QAT later in this book.

11

12

Excel Names -- Named Ranges


You can create Excel names that refer to cells, a range of cells, a constant value, or a formula. After you
define the names, you can use those names in formulas, to replace values or cell references. If Excel names
refer to cells or a range of cells, you can use the names for navigation, to quickly select the named range.
Name a Range of Cells
In Excel; you can create names that refer to a single cell, a group of cells on the worksheet, a specific value,
or a formula. After you define Excel names, you can use the names in a formula, instead of using a constant
value or cell references. For example, a cell that contains the tax rate could be named SalesTax. Then,
other cells could multiply sales amounts by the named range, SalesTax.
For Excel names that refer to a cell or a range of cells, you can use the names to quickly select the named
range, and that makes navigation easier. Just select a range name from a drop down list, and you'll
immediately go to that range.
Name a Range - Name Box
You can create a named range quickly by typing in the Name Box.
1.
2.
3.
4.

Select the cell(s) to be named


Click in the Name box, to the left of the formula bar
Type a one-word name for the list, e.g. FruitList.
Press the Enter key.

Create Names from Worksheet Labels


A quick way to create names is to base them on worksheet labels. In the example shown below, the cells in
column C will be named, based on the labels in the
adjacent cells, in column B.

To name cells, or ranges, based on worksheet labels:

13

1. Select the labels and the cells that are to be named. The labels
can be above, below, left or right of the cells to be named. In this
example, the labels are in column B, to the left of the cells that will be named.

2. On the Ribbon, click the Formulas tab, and then click Create from Selection.

3. In the Create from Selection window, add a check mark for the location of the labels, and then click
OK. In this example, the labels are in the left column of the selected cells.

4. Click on a cell to see its name. In the screen shot below, cell C4 is selected, and you can see its
name in the Name Box -- Full_Name.
o NOTE: If the labels contain spaces, they're replaced with an underscore. Other invalid
characters, such as & and # will be removed, or replaced by an underscore character.

14

Use Names
After creating names that refer to a range, you can select a name in the Name Box dropdown list, to select
the named range on the worksheet.
You can also use names in formulas. For example, you could have a group of cells with sales amounts for
the month of January. Name those cells JanSales, and then use this formula to calculate the total amount:
=SUM(JanSales)
In the following example, the names TotalSales and TaxRate have been defined.
=TotalSale * TaxRate

15

Remove Duplicates
In Excel 2007, there's a new command on the Ribbon to make it easier to remove duplicates from a list.
How It Works
In this example, the list in cells A1:A10 contains a few duplicates.

Follow these steps to remove the duplicates.


1. Select any cell in the list, or select the entire list
2. On the Ribbon's Data tab, click Remove Duplicates.

3. In the Remove Duplicates dialog box, select the column(s) that you want to remove duplicates from
4. Check the box for My Data Has Headers, if applicable, then click OK.

16

5. A confirmation message will appear, showing the number of duplicates removed, and the number
of unique items remaining. Click OK to close the message.

17

Data Validation
In Excel, the data validation feature helps you control what can be entered in your worksheet. For
example, you can:

create a drop down list of items in a cell


Restrict entries, such as a date range or whole numbers only
create Custom rules for what can be entered

Create a Drop Down List - Instructions


With Data Validation, you can create a dropdown list of options in a cell. Although you can type the list
directly into the Data Validation dialog box, it's best to use a table on the worksheet, as described below.
Note: Data validation is not foolproof. It can be circumvented by pasting data into the cell, or by choosing
Clear > Clear All, on the Ribbon's Home tab.
Create a Table
The easiest way to create and maintain the list of options is to type them on a worksheet. You can do this
on the sheet that will contain the drop down lists, or on a different sheet. In this
example, the list will be stored on a sheet named Lists.
1. Type a heading for the list -- Employees in this example
2. Immediately below the heading cell, in single column, type the entries you
want to see in the drop down list. Do not leave blank cells between the
entries.
3. Select a cell in the list, and on the Ribbon's Insert tab, click Table
4. Add a check mark in "My table has Headers" and click OK

The table is now a Named Excel Table.

18

Name the List Range


Next, you will create a named range that does not include the heading cell in the table. This named range
will be dynamic -- it will adjust automatically if items are added to or deleted from the list.
1. Click at the top of the heading cell, to select all the cells in the list (without the heading).

2. Click in the Name box, to the left of the formula bar


3. Type a one-word name for the list, e.g. EmpNames.
4. Press the Enter key, to complete the naming process. (After you press Enter, the name will
disappear, and the Table name will appear in the name box.)

Apply the Data Validation


Now that you have created a named range, you can use that to create a drop down list in one or more cells
1.
2.
3.
4.

Select the cells in which you want the drop down list
On the Ribbon's Data tab, click Data Validation.
From the Allow drop-down list, choose List
Click in the Source box, and type an equal sign, and the list name, for example:
=EmpNames
OR, press the F3 key, to see a list of names, click on a name, and click OK
19

5. Click OK to close the Data Validation dialog box.

20

Relative, Absolute AND Mixed Cell Reference


When we copy formulas that contain cell references to other cells, then we need to understand that there are
four types of cell references:

1.
2.
3.
4.

Relative
Absolute
Mixed Cell Reference with Column Locked also known as Column Absolute, Row Relative
Mixed Cell Reference with Row Lockedalso known as Row Absolute, Column Relative

It will only be possible to understand these if we look at a few examples. Nevertheless, here are the crucial facts
about cell references:

1. Relative Cell References

Example: A1

No dollar signs
Moves relatively throughout copy action

Relatively means that if the formula is looking at a cell reference that is three cells to the left,
when you copy the formula to any other cell, the cell reference will still be looking three cells to the
left.

2. Absolute Cell References

Example: $A$1

Dollar signs before both:


Column designation = A
Row designation = 1
Absolute means that if the formula is looking at a particular cell reference, when you copy the
formula to any other cell, the cell reference will still be looking at that particular cell reference.
If the Absolute Cell reference is $A$1, the formula will always look at cell A1. It is as if the formula is
locked on the cell A1 throughout copy action
Locks cell reference when copying it horizontally and vertically

3. Mixed Cell Reference with Column Locked

Example: $A1

Dollar sign before column designation


Remains absolute or locked when copying across columns
Remains relative when copying across rows
Locks cell reference when copying it horizontally, but not vertically

21

4. Mixed Cell Reference with Row Locked

Example:

A$1
Dollar sign before row designation
Remains absolute or locked when copying across rows
Remains relative when copying across columns
Locks cell reference when copying it vertically, but not horizontally
Keyboard shortcut F4 key:Toggles between the four types of cell references

When creating formulas with cell references, ask two questions of every cell reference in formula:
Q1: What do you want it to do when you copy it horizontally?
Is it a relative reference? OR
Is it an absolute or locked reference?
Q2: What do you want it to do when you copy it vertically?
Is it a relative reference? OR
Is it an absolute or locked reference?

22

23

Create Basic Formulas


Definition of a formula: Anything in a cell when the first character is an equal sign.
(The long version: anything in a cell or formula textbox when the first character is an equal sign and the
cell is not preformatted as Text.)
Advantages of a formula: You are telling Excel to do calculations, look into another cell, create text
strings, or deliver a range
How to create a formula: Type =, followed by:
1.
2.
3.
4.
5.
6.
7.
8.
9.

Equal sign (starts all formulas)


Cell references (also defined names, sheet references, workbook references)
Math operators (plus, subtract, multiply, and so on)
Numbers (if the number will not change; for example, 12 months, 24 hours)
Built-in functions (AVERAGE, SUM, COUNTIF, DOLLAR, PMT, and so forth)
Comparative operators (=, >, >=, <, <=, <>)
The ampersand join symbol (&) (Shift + 7)
Text within quotation marks (for example, For the Month Ended)
Array constants (for example, {1,2,3})

How to enter a formula into a cell: hit one of the following:


10. ENTER (Active Cell goes down)
11. Ctrl + Enter (Active Cell remains the same)
12. Tab(Active Cell goes left)
13. Shift + Tab (Active Cell goes right)
14. Shift + Enter(Active Cell goes up)

24

Calculate with Functions


What are functions? Built in code that will do complicated math (and other tasks) for you after you tell
it which cells to look in
Examples:
SUM function (adds)
AVERAGE function (arithmetic mean)
PMT function (calculate loan payment)
COUNT function (counts numeric values)
COUNTA function (counts non-blank cells)
COUNTIF function (counts based on a condition)
ROUND function (round a number to a specified digit)
IF function (Puts one of two items into cell depending on whether the condition evaluates to true or
false)

25

SUM FUNCTIONS
Sum a range of cells -- SUM Function
The SUM function will add the numbers in a range of cells. Its syntax is:
=SUM(number1, number2,...number30).
The arguments (e.g. number1) for the SUM function can be cell references, or typed into the formula. The
following example uses one argument -- a reference to cells A1:A4.
1. Select the blank cell in the row below the cells that you want to sum, cell A5 in this example.
2. Click the AutoSum command on the Ribbon's Home tab

Or, use the keyboard shortcut: Alt + =


A SUM formula will appear in the active cell, with a reference to the cells above. If the cells are not
automatically included, you can drag over the cells, to select them.

3. Press the Enter key to complete the entry.


Note: Instead of using the AutoSum button, you can type the SUM formula into the cell.

26

Grand Total a range of cells


You can calculate row totals, column totals, and a grand total for a range of cell, all in one step.
1. Select the range of cells, and the blank row below the range, and the blank cells in the column to
the right (cells A1:D5 in the example below)

2. Click the AutoSum button on the Ribbon's Home tab. A SUM formula will be automatically entered
for each Total.
Sum cells that match criteria -- SUMIF
Match criterion exactly
You can calculate a total for rows that meet a specific criterion. In this example only the rows with Pen
orders will be included in the total.
1.
2.
3.
4.

Select the cell in which you want to see the total


Type an equal sign (=) to start the formula
Type: SUMIF(
Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will
be checked
5. Type a comma, to separate the arguments
6. Type the criterion. In this example, you're checking for text, so type the word in double quotes:
"Pen"
Note: upper and lower case are treated equally
7. Type a comma, to separate the arguments
8. Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed
9. The completed formula is:
=SUMIF(A2:A10,"Active",B2:B10)
10. Press the Enter key to complete the entry

27

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9
above could be changed to:
=SUMIF(A2:A10, B12, B2:B10)
if cell B12 contained the text pen.
Match criterion in a string
You can add cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and
Pencil orders will be summed, because they contain the string "pen".
1.
2.
3.
4.

Select the cell in which you want to see the total (cell A12 in this example)
Type an equal sign (=) to start the formula
Type: SUMIF(
Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will
be checked
5. Type a comma, to separate the arguments
6. Type the criterion. In this example, you're checking for text, so type the word in double quotes,
with one or more asterisk (*) wildcard characters: "*Pen*"
Note: upper and lower case are treated equally
7. Type a comma, to separate the arguments
8. Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed
9. Type a closing bracket. The completed formula is: =SUMIF(A2:A10,"*Pen*",B2:B10)
10. Press the Enter key to complete the entry
11. The result will be 53, the total of rows that contain the string, "Pen"

28

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9
above could be changed to:
=SUMIF(A2:A10,"*" & B12 & "*",B2:B10)
if cell B12 contained the text pen.
Criterion and operator
You can use an operator with a criterion. In this example only the rows where the number of sales reps is
greater than or equal to ten will be included in the total.
1.
2.
3.
4.

Select the cell in which you want to see the total


Type an equal sign (=) to start the formula
Type: SUMIF(
Select the cells that contain the values to check for the criterion. In this example, cells B2:B10 will
be checked
5. Type a comma, to separate the arguments
6. Type the criterion. In this example, you're checking for rows where the number of visits is greater
than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed
in double quotes.
7. Type a comma, to separate the arguments
8. Select the cells that contain the values to sum
9. Type a closing bracket. The completed formula is:
=SUMIF(B2:B10,">=10",C2:C10)
10. Press the Enter key to complete the entry
11. The result will be 183, the total of rows with ten or more sales reps.

29

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9
above could be changed to:
=SUMIF(B2:B10,">=" & B12,C2:C10)
if cell B12 contained the number 10.
Sum cells that match multiple criteria -- SUMIFS
Match multiple criteria
In Excel 2007 and later versions, you can use the SUMIFS function to calculate a total for rows that meet
two or more criteria. In this example only the rows where the status is "Active" and the number of visits is
greater than or equal to ten will be included in the total.

1. Select the cell in which you want to see the total


2. Type an equal sign (=) to start the formula
30

3. Type: SUMIFS(
4. Select the cells that contain the values to sum. In this example,
cells C2:C6 will be summed
5. Type a comma, and then select the cells that contain the values to check for the first criterion. In
this example, cells A2:A6 will be checked
6. Type a comma, and then type the first criterion, "Active"
7. Type a comma, and then select the cells that contain the values to check for the second criterion. In
this example, cells B2:B6 will be checked
8. Type a comma, and then type the second criterion: " >=10"
9. Finish with a closing bracket: )
10. The completed formula is:
=SUMIFS(C2:C6,A2:A6,"Active",B2:B6,">=10")
11. Press the Enter key to complete the entry
Sum the Top 5 Numbers in a List
Use the SUM function and LARGE functions together, to add the largest numbers in the list.
Version 1 -- Few Top Numbers
If a few numbers are to be summed, e.g. top 3, you can type the numbers into the formula. For example:
=SUM(LARGE(A1:A7,{1,2,3}))
The result is 70+60+50 = 180
Note: The second 50 is not included in the result, even though it is tied for 3rd place.

Version 2 -- Many Top Numbers


If many top numbers are to be summed you can include the INDIRECT function in the formula with the
SUM function. In the INDIRECT function, use row numbers that represent the numbers you want to
31

include. In this example, rows 1:10 are used, so the top 10 numbers in
the referenced range will be summed.
1. Type the formula:
=SUM(LARGE(A1:A50,ROW(INDIRECT("1:10"))))
2. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and
press Enter
Version 3 -- Variable Top Numbers
If a variable number of top numbers are to be summed you can include the INDIRECT function in the
formula with the SUM function, as shown above, and refer to a cell that holds the variable..
1. In cell C1, type the number of top cells, e.g. 10
2. Type the formula:
=SUM(LARGE(A1:A7,ROW(INDIRECT("1:"&C1))))
3. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and
press Enter

32

Count Functions
How to count Excel cells with numbers, text, blanks, or cells that contain specific words or other criteria?
Count Cells with Numbers -- Excel COUNT
The COUNT function will count cells that contain numbers. Its syntax is:
=COUNT(value1, value2,...value30).
The arguments (e.g. value1) can be cell references, or values typed into the COUNT formula.
The following COUNT function example uses one argument -- a reference to cells A1:A5.
1. Enter the sample data on your worksheet
2. In cell A7, enter an COUNT formula, to count the numbers in column A: =COUNT(A1:A5)

3. Press the Enter key, to complete the formula.


4. The result will be 3, the number of cells that contain numbers.
Cell A1 isn't counted, because it contains text.
Note: Since dates are stored as numbers, the COUNT function will include any cells that contain dates.
Count Cells with Data -- COUNTA
The COUNTA function will count cells that are not empty. Its syntax is:
=COUNTA(value1, value2,...value30).
The arguments (e.g. value1) can be cell references, or values typed into the formula. The following
example uses one argument -- a reference to cells A1:A5.
1. Enter the sample data on your worksheet
2. In cell A7, enter a COUNTA formula, to count the numbers in column A: =COUNTA(A1:A5)

33

3. Press the Enter key, to complete the formula.


4. The result will be 4, the number of cells that contain data.
Note: COUNTA will count cells with formulas including those that look empty, because they evaluate to
"", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but then were
converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank" converted
cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys."
Count Blank Cells -- COUNTBLANK
The COUNTBLANK function will count cells that are empty. Its syntax is:
=COUNTBLANK(range).
The following example uses a reference to cells A1:A5.
1. Enter the sample data on your worksheet
2. In cell A7, enter a COUNTBLANK formula, to count the numbers in column A:
=COUNTBLANK(A1:A5)

3. Press the Enter key, to complete the formula.


4. The result will be 1, the number of empty cells.
Note: COUNTBLANK will count cells with formulas including those that look empty, because they
evaluate to "", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but
then were converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank"
converted cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys."

34

Count cells that match criteria -- COUNTIF


Match criterion exactly
In Excel, count cells that meet a specific criterion. In this example only the Pen orders will be counted.
1.
2.
3.
4.

Select the cell in which you want to see the count (cell A12 in this example)
Type an equal sign (=) to start the formula
Type: COUNTIF(
Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will
be checked
5. Type a comma, to separate the arguments
6. Type the criterion. In this example, you're checking for text, so type the word in double quotes:
"Pen"
Note: upper and lower case are treated equally
7. Type a closing bracket
The completed formula is: =COUNTIF(A1:A10,"Pen")

8. Press the Enter key to complete the entry


9. The result will be 4, the number of cells that contain "Pen"
Match criterion in a string
In Excel, count cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen,
and Pencil orders will be counted, because they contain the string "pen".
1. Select the cell in which you want to see the count (cell A12 in this example)
2. Type an equal sign (=) to start the formula
3. Type: COUNTIF(

35

4. Select the cells that contain the values to check for the criterion.
In this example, cells A1:A10 will be checked
5. Type a comma, to separate the arguments
6. Type the criterion. In this example, you're checking for text, so type the word in double quotes,
with one or more asterisk (*) wildcard characters: "*Pen*"
Note: upper and lower case are treated equally
7. Type a closing bracket
The completed formula is: =COUNTIF(A1:A10,"*Pen*")

8. Press the Enter key to complete the entry


9. The result will be 6, the number of cells that contain the string, "Pen"
Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 7
above could be changed to:
=COUNTIF(A1:A10,"*" & B12 & "*")
if cell B12 contained the text pen.
Criterion and operator
You can use an operator with a criterion. In this example only the rows where the quantity is greater than
or equal to ten will be counted.
1.
2.
3.
4.

Select the cell in which you want to see the count (cell A12 in this example)
Type an equal sign (=) to start the formula
Type: COUNTIF(
Select the cells that contain the values to check for the criterion. In this example, cells B1:B10 will
be checked
5. Type a comma, to separate the arguments

6. Type the criterion. In this example, you're checking for rows where the quantity is greater than or
equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in
36

double quotes: ">=10"


Note: Even though this is a numerical criterion, it must enclosed
in double quote marks.
7. Type a closing bracket
8. The completed formula is:
=COUNTIF(B1:B10,">=10")
9. Press the Enter key to complete the entry

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8
above could be changed to:
=COUNTIF(B1:B10,">=" & B12)
if cell B12 contained the number 10.
Match criteria in a range
You can combine COUNTIF formulas, to count rows that are within a range of values. In this example, the
formula will count rows where the quantity is between 5 and 10 (inclusive).
1. Select the cell in which you want to see the count (cell A12 in this example)
2. Type a formula to count rows greater than or equal to 5:
=COUNTIF(B1:B10,">=5")
3. Type a minus sign
4. Type a formula to count rows greater than 10:
COUNTIF(B1:B10,">10")
5. The completed formula is:
=COUNTIF(B1:B10,">=5")-COUNTIF(B1:B10,">10")
6. Press the Enter key to complete the entry

37

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8
above could be changed to:
=COUNTIF(B1:B10,">=" & B12) COUNTIF(B1:B10,">" & C12)
if cell B12 contained the number 5 and cell C12 contained the number 10.
Change Operator for COUNTIF Function
Instead of typing the operator into the COUNTIF formula, as shown above, you can create a list of all
possible operators, and select one from a drop down list. Then, refer to that operator in the formula.
Create a Drop Down List of Operators
To create a drop down list operators:
1. On a different sheet in the workbook, type a list of operators in a column.
2. Select the cells in the list, and Name that list as OpList.

3. On the main sheet, select the cell where you want the drop down list.
4. Use the data validation command to create the drop down list, based on the named range -- OpList
38

Use the Drop Down List


Change your COUNTIF formula, to replace the typed operator with a reference to the cell with the drop
down list.

Select one of the operators, from the drop down list, and the formula result will change.
Count cells that match multiple criteria -- COUNTIFS

Match multiple criteria


In Excel 2007 and later versions, you can use the COUNTIFS function to count rows that meet two or more
criteria. In this example only the row where the item is "Pen" and the quantity is greater than or equal to
ten will be counted.
1. Select the cell in which you want to see the total
2. Type an equal sign (=) to start the formula
3. Type: COUNTIFS(
39

4. Select the cells that contain the values to check for the first
criterion. In this example, cells A2:A10 will be checked
5. Type a comma, and the first criterion: "Pen"
Note: Because this is a text criterion, it is enclosed in double quote marks.
6. To start the next set of criteria, type a comma
7. Select the cells that contain the values to check for the second criterion. In this example,
cells B2:B10 will be checked
8. Type a comma, and the second criterion: ">=10"
Note: Because this criterion includes operators, it is enclosed in double quote marks. To count rows
where the quantity is equal to 10, only the number 10 would be required.
9. Finish with a closing bracket: )
10. The completed formula is shown below.
11. Press the Enter key to complete the entry

Note: Instead of typing the criterion in a formula, you can refer to a cell, as shown in the second formula
below. If using operators, enclose them in double quote marks.

Use typed criteria:


=COUNTIFS(A2:A10,"Pen",B2:B10,">=10")
or cell references:
=COUNTIFS(A2:A10,D3,B2:B10,">=" & E3)

40

IF FUNCTION
In this next section we will talk about a built-in Excel function called the IF function. The IF function is great
for when you need to put one of two things into a cell. For example, when you are calculating whether or
not you get a bonus at work, you would say something like, If I make sales over or equal to $5,000, I get a
$100 bonus, otherwise I get no bonus. Notice that the words that we use to describe whether or not we
get a bonus start with the word If! This is why Excel named the function IF.
In our case the logical test would be: Sales >=$5,000 (in words: If I make sales over or equal to $5,000).
This logical test will either be TRUE or FALSE. If the logical test is TRUE, then we get our bonus of $100. If
the logical test is FALSE, then we get a bonus of $0 (we did not exceed or equal the sales hurdle of $5,000).
Thebuilt-in Excel IF function will automatically tell you whether or not you earned a bonus! All you have to
do is tell the IF function three things:
1. What the logical test is
2. What the bonus amount is (Value to put in the cell if the logical test turns out to be TRUE)
3. What the amount is if we dont make the sales hurdle. (Value to put in the cell if the logical test
turns out to be FALSE)
In Excel language (and math language) the three things are called arguments. So our three arguments for
the IF function will be:
1) Logical test
2) Value if TRUE
3) Value if FALSE
The function will look like this:
=IF(logical_test,[value_if_true],[value_if_false])
The great thing about the IF function is that whenever you have one of two things to put in a cell that
depend of a logical test that comes out to be TRUE or FALSE, you can use the IF function. In addition, the
two things that you want to put in a cell that depend on a logical test can be numbers, text, cell references,
or other formulas.

41

Steps to see four examples of the IF function:


1. Navigate to the sheet named IF function. As seen, there are four screen tips that I have added
to show you the formulas that will help you see the different ways the IF function can be used.
We will go step by step through the first one and then you can try the remaining ones on your
own (there are even two more very complicated IF examples if you scroll down further in the
sheet).

2. Click in cell B14 and type the beginning few characters of our formula: =IF(. In Next Figure you
can see the beginning characters of our formula in the cell B14 and in the formula bar. You can
also see a function screen tip that gives you a hint of what arguments are required.

=IF(

Function Screen Tip

42

3. Type the logical test, this logical test says If Sales are greater
than or equal to the Sales Hurdle. This logical test will come
out to be TRUE or FALSE.

4. Next, we type a comma. As seen, the screen tip highlights with bold the next argument that is
needed. We can see that we must tell the IF function what to put in the cell if the logical test
comes out to be TRUE.

5. As seen, in order to tell the function what value goes into the cell if the logical test is TRUE, we
click on the cell with the $100 bonus, cell B11.

6. As seen, we complete the formula by adding the last argument and ending parenthesis to our IF
function. This last argument tells the IF function what to put in the cell if the logical test is
FALSE.

Hit control + Enter to enter our formula into the cell. As seen in Figure 369, the IF function delivers the
$100 bonus to the cell because our Sales number, $5,500, is above the Sales Hurdle number, $5,000. But
what if our mean boss changed the Sales Hurdle number to $6,000? What would happen to our $100
Bonus?

43

7. To see the IF function in action, pretend you are the mean boss and change the Sales Hurdle
value in cell B10 to the value $6,000 (which is above your Sales number. As seen, the IF function
looked at the logical test Sales>=$6,000 ($5,5000>=$6,000), came to a FALSE conclusion, and
then put the $0 amount in cell B14.

8. Now change your Sales number to $6,000. As seen, because the logical test Sales>=$6,000
($6,000>=$6,000) was TRUE, the TRUE amount of $100 was put into cell B14.

Before you try the remaining IF functions on your own, lets look at the completed IF function formula in
cell A19 in our formula bar. Here we can see that the logical test is whether or not Sales are greater than
Expenses (Sales>=Expenses), if this is TRUE, we want out label to read Net Income, otherwise if it is
FALSE, we want our label to read Net Loss.

44

9. we can see that if we were to change or Expenses to be


$7,000, the labels updates because the IF function formula
puts the words Net Loss in the cell because the logical test evaluates to FALSE.

45

VLOOKUP FUNCTION
The VLOOKUP function looks for a value in the first column in a table, and returns another value from the
same row in that table.

How Could You Use VLOOKUP?


The VLOOKUP function can find exact matches in the lookup column, or the closest match, so it can:

Find the price of a selected product


Convert student percentages to letter grades

VLOOKUP Syntax
The VLOOKUP function has the following syntax:

VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
o lookup_value: the value that you want to look for -- it can be a value, or a cell reference.
o table_array: the lookup table -- this can be a range reference or a range name, with 2 or
more columns.
o col_index_num: the column that has the value you want returned, based on the column
number within the table.
o [range_lookup]: for an exact match, use FALSE or 0; for an approximate match, use TRUE or
1, with the lookup value column sorted in ascending order..

VLOOKUP Traps
VLOOKUP can be slow, especially when doing a text string match, in an unsorted table, where an exact
match is requested. Wherever possible, use a table that is sorted by the first column, in ascending order,
and use an approximate match. You can use MATCH or COUNTIF to check for the value first, to make sure
it is in the table's first column (see example 3 below).
Other functions, such as INDEX and MATCH, can be used to return values from a table, and are more
efficient. We'll look at those functions later in the challenge, and see how flexible and powerful they are.

46

Example 1: Find the Price for a Selected Item


The VLOOKUP function looks for a value in the left column of the lookup table. In this example, we'll find
the price for a selected product. It's important to get the correct price, so the following settings are used:

a product name is entered in cell B7


the pricing lookup table has two columns, and is in range B3:C5
price is in column 2 of the table.
FALSE is used in the last argument, to find an exact match for the lookup value.

The formula in cell C7 is:


=VLOOKUP(B7,B3:C5,2,FALSE)

If the product name is not found in the first column of the lookup table, the VLOOKUP formula result is
#N/A

Example 2: Convert Percentages to Letter Grades

47

Usually, an exact match is required when using VLOOKUP, but


sometimes an approximate match works better. For example, when
converting student percentages to letter grades, you wouldn't want to type every possible percentage in
the lookup table. Instead, you could enter the lowest percentage for each letter grade, and then use
VLOOKUP with an approximate match. In this example:

a percentage is entered in cell C9


the percentage lookup table has two columns, and is in range C3:D7
the lookup table is sorted by the percentage column, in ascending order
letter grade is in column 2 of the table.
TRUE is used in the last argument, to find an approximate match for the lookup value.

The formula in cell D9 is:


=VLOOKUP(C9,C3:D7,2,TRUE)
If the percentage is not found in the first column of the lookup table, the VLOOKUP formula result is the
next largest value that is less than lookup_value. The lookup value in this example is 77. That value is not in
the percentage column, so the value for 75 (B) is returned.

Example 3: Find Exact Price With Approximate Match


The VLOOKUP function can be slow when doing an exact match for a text string. In this example, we'll find
the price for a selected product, without using the Exact Match setting. To prevent incorrect results:

the lookup table is sorted by the first column, in ascending order


COUNTIF checks for the value, to prevent incorrect results

The formula in cell C7 is:


=IF(COUNTIF(B3:B5,B7),VLOOKUP(B7,B3:C5,2,TRUE),0)
48

If the product name is not found in the first column of the lookup table, the VLOOKUP formula result is 0.

49

SEARCH FUNCTION
The SEARCH function looks for a text string, within another text string, and returns its position, if found. It
is not case sensitive.

How Could You Use SEARCH?


The SEARCH function looks for a text string, within another text string, and it can:

Find a text string within another text string not case sensitive
Use wildcards in the search
Specify a start number within search text

SEARCH Syntax
The SEARCH function has the following syntax:

SEARCH(find_text,within_text,start_num)
o find_text is the text that you're looking for.
o within_text is the string that you're searching in.
o if start_num is omitted, the search starts with the first character

SEARCH Traps
The SEARCH function will return the position of the first matching string, regardless of case. If you need a
case sensitive search, use the FIND function, which we'll see later in the 30XL30D challenge.
Example 1: Find Text in a String
Use the SEARCH function to look for text within a text string. In this example, we're looking for a single
character (entered in cell B5), within a text string in cell B2.

=SEARCH(B5,B2)
50

If the text is found, the SEARCH function returns the number of its
starting position in the text string. If it's not found, the result is a
#VALUE! error.
You could use IFERROR to wrap the SEARCH function, and display a message, if the result is an error. The
IFERROR is available in Excel 2007 and later versions. For earlier versions, you can use IF with ISERROR.
=IFERROR(SEARCH(B5,B2),"Not Found")

Example 2: Use wildcards with SEARCH


Another way to check the SEARCH results is with the ISNUMBER function. If the string is found, the SEARCH
result is a number, so the ISNUMBER result is TRUE. If the text is not found, SEARCH results in an error, and
ISNUMBER returns FALSE.
You can also use wildcards in the find_text argument. The * (asterisk) represents any number of
characters, or no characters, and the ? (question mark) represents a single character.
In this example, the * wildcard is used, so central, center and centre are all found in the street addresses.
=ISNUMBER(SEARCH($E$2,B3))

51

Example 3: Specify Start Number for SEARCH


By typing two minus signs (double unary) in front of the ISNUMBER function, it returns 1/0 instead of
TRUE/FALSE. Then, a SUM function in cell E2 can total the number of records where the text string was
found.
In this example, City and Occupation are shown in column B. We want to find all occupations with the text
string entered in cell E1. The formula in cell C2 is:
=ISNUMBER(SEARCH($E$1,B2))
The formula found the string that contain "bank", but one of those is in a City name, not the occupation:

There is a pipe character after each city name, so we can add a SEARCH for that. Its position can be used as
the start_number argument in the main SEARCH, so the cities will be ignored when searching.
Now, with the revised formula, only the rows with "bank" in the occupation are counted.
=ISNUMBER(SEARCH($E$1,B2,SEARCH("|",B2)))

52

53

INDEX FUNCTION
The INDEX function returns a value or reference to a value. Combine it with other functions, like MATCH,
for powerful formulas.

How Could You Use INDEX?


The INDEX function can return a value or reference to a value, so you can use it to:

Find sales amount for selected month


Get reference to specified row, column, area
Create a dynamic range based on count
Sort column of text in alphabetical order

INDEX Syntax
The INDEX function has two syntax forms -- Array and Reference. With Array form, a value is returned, and
with Reference form, a reference is returned.
The Array form has the following syntax:

INDEX(array,row_num,column_num)
o array is an array constant or range of cells
o if array has only 1 row or column, corresponding row/column number argument is optional
o if array has >1 row or column, and only row_num or column_num is used, array of entire
row or column is returned
o row_num if omitted, column_num is required
o column_num if omitted, row_num is required
o if both the row_num and column_num arguments are used, returns value in cell at
intersection of row_num and column_num
o if row_num or column_num are zero, returns array of values for entire column or row

The Reference form has the following syntax:


54

INDEX(reference,row_num,column_num,area_num)
o reference can refer to one or more cell ranges enclose
nonadjacent ranges in parantheses
o if each area in reference has only 1 row or column, corresponding row/column number
argument is optional
o area_num selects range in reference from which to return row and column intersection
o area_num if omitted, area 1 is used
o if row_num or column_num are zero, returns reference for entire column or row
o result is a reference, and can be used by other functions

INDEX Traps
If the row_num and column_num don't point to a cell within the array or reference, the INDEX function
returns a #REF! error.
Example 1: Find sales amount for selected month
Enter a row number, and the INDEX function returns the sales amount from that row in the reference.
Here the month number is 4, so the April sales amount is returned.
=INDEX($C$2:$C$8,F2)

To make the formula more flexible, you could use MATCH to return the row number, based on the month
that was selected from a drop down list.
=INDEX($C$2:$C$8,MATCH($F$2,$D$2:$D$8,0))

55

Example 2: Get reference to specified row, column, area


In this example, there is a named range, MonthAmts, which consists of 3 non-contiguous ranges. The
MonthAmts range has 3 areas -- one for each month -- and there are 4 rows and 2 columns in each area.
Here is the formula for the MonthAmts name:
='Ex02'!$B$3:$C$6,'Ex02'!$E$3:$F$6,'Ex02'!$H$3:$I$6
With the INDEX function, you can return the cost or revenue amount for a specific region and month.
=INDEX(MonthAmts,B10,C10,D10)

The INDEX function result can be multiplied, as in the Tax calculation in cell F10:
=0.05*INDEX(MonthAmts,B10,C10,D10)

or, it can return a reference for the CELL function, to show the address of the result, in cell G10.
56

=CELL("address",INDEX(MonthAmts,B10,C10,D10))

Example 3: Create a dynamic range based on count


You can also use the INDEX function to create a dynamic range. In this example, I've created a name,
MonthList, with this formula:
='Ex03'!$C$1:INDEX('Ex03'!$C:$C,COUNTA('Ex03'!$C:$C))

If another month is added to the list in column C, it will automatically appear in the data validation drop
down list in cell F2, which uses MonthList as its source.

57

Example 4: Sort column of text in alphabetical order


In the final example, the INDEX function is combined with several other functions, to return a list of
months, sorted in alphabetical order. The COUNTIF function shows how many month names come before a
specific month name. SMALL returns the nth smallest item in the list, and MATCH returns the row number
for that month.
In the video, you can see the formula broken down into steps.
This formula is array-entered, by pressing Ctrl + Shift + Enter.
=INDEX($C$4:$C$9,MATCH(SMALL(
COUNTIF($C$4:$C$9,"<"&$C$4:$C$9),ROW(E4)-ROW(E$3)),
COUNTIF($C$4:$C$9,"<"&$C$4:$C$9),0))

58

59

MATCH FUNCTION
The MATCH function returns the position of a value in an array, or #N/A if not found. The array can be
sorted, or unsorted, and the MATCH function is not case sensitive.

How Could You Use MATCH?


The MATCH function returns the position of an item in an array, and that result can be used by other
functions, such as INDEX or VLOOKUP. For example:
Find position of item in unsorted list
Use with CHOOSE to get student grades
Use with VLOOKUP for flexible column choice
Use with INDEX for to show winner's name
MATCH Syntax
The MATCH function has the following syntax:
MATCH(lookup_value,lookup_array,[match_type])
lookup_value can be text, number or logical value
lookup_array is an array, or array reference (contiguous cells in a single row or column)
match_type can be -1, 0 or 1. If omitted, assumed to be 1
MATCH Traps

MATCH function returns the position of the item found, not the value. If you need the value, combine
MATCH with another function, like INDEX.
60

Example 1: Find Item in Unsorted List


For an unsorted list, you can use 0 as the match_type argument, to find an exact match. If you're searching
for text, and using 0, you can include wildcard characters in the lookup value.
In this example, you can type a month name, or partial name with wildcards, to find that month's position
in the list.
=MATCH(D2,B3:B7,0)

Instead of an array reference, you can enter an array as the lookup_array argument. In this variation, the
lookup month name is entered in cell D5, and three month names are entered in the MATCH function's
second argument. If a later month, such as Oct, is entered in D5, the result will be #N/A.
=IF(C2+0<14,"Time to upgrade","Latest version")

Example 2: Change Student Grades to Letters

Just as you did with VLOOKUP, you can use MATCH to help convert a student's score to a letter grade. In
this example, it is combined with CHOOSE, to get the letter grade. The match_type is -1, because the
scores are sorted in descending order.

61

When the match_type is -1, the result is the smallest value greater than
or equal to lookup value. The lookup value is 54, and it's not in the list of
scores, so the position for 60 is returned. Because 60 is in position 4, the 4th value in the CHOOSE options
is the result -- cell C6, with a value of D.
=CHOOSE(MATCH(B9,B3:B7,-1),C3,C4,C5,C6,C7)

Example 3: Create Flexible Column Choice in VLOOKUP


To make a VLOOKUP formula more flexible, you can use MATCH to find a column number, instead of hardcoding it into the formula. In this example, users can select a region in cell H1, as the value for the
VLOOKUP. Then, they can select a Month in cell H2, and the MATCH function returns the column for that
month.
=VLOOKUP(H1,$B$2:$E$5,MATCH(H2,B1:E1,0),FALSE)

Example 4: FIND Closest Match with INDEX

62

The MATCH function also works well with the INDEX function, which
we'll see later in the challenge. In this example, the MATCH function is
used to find the guess that is closest to the correct number.
The ABS function returns the absolute difference between each guess and the correct number.
The MIN function finds the smallest difference.
The MATCH function finds the smallest difference in the list of differences. If there are multiple identical
differences, the first one will be returned.
The INDEX function returns the name in that position in the list of names.
=INDEX(B2:B5,MATCH(MIN(ABS(C2:C5-F1)),ABS(C2:C5-F1),0))

INDIRECT FUNCTION
The INDIRECT function returns the reference specified by a text string.

How Could You Use INDIRECT?


63

The INDIRECT function returns the reference specified by a text string, so


you can use it to:

Create starting reference that doesn't shift


Create reference to static named range
Create reference from sheet, row, column info
Create array of numbers that doesn't shift

INDIRECT Syntax
The INDIRECT function has the following syntax:

INDIRECT(ref_text,a1)
o ref_text is the text string for a reference.
o a1 if TRUE or omitted, uses an A1 reference style; if FALSE, the R1C1 reference style is used

INDIRECT Traps

The INDIRECT function is volatile, so it could slow down your workbook, if used in many formulas.
If the INDIRECT function creates a reference to another workbook, that workbook must be open, or
the formula will result in a #REF! error.
If the INDIRECT function creates a reference to a range outside the row and column limit, the
formula will result in a #REF! error. (Excel 2007 and Excel 2010)
The INDIRECT function cannot resolve a reference to a dynamic named range

Example 1: Create starting reference that doesn't shift


In the first example, there are identical numbers in columns C and E, and the totals are the same, using the
SUM function. However, the formulas are slightly different. In cell C8, the formula is:
=SUM(C2:C7)
In cell E8, the INDIRECT function creates a reference to the starting cell, E2:
=SUM(INDIRECT("E2"):E7)

64

If a row is inserted at the top of the lists, and January amounts are entered, the total in column C doesn't
change. The formula changed, adjusting to the inserted row:
=SUM(C3:C8)
However, the INDIRECT function locked the starting cell to E2, so the January amount is automatically
included in the column E total. The ending cell changed, but the starting cell wasn't affected.
=SUM(INDIRECT("E2"):E8)

Example 2: Create reference to static named range

65

The INDIRECT function can also create a reference for a named range. In
this example, the blue cells are in a range named NumList. There is also a
dynamic range in column B, based on the count of numbers in that column.
The total for either range can be calculated, by using the range name with the SUM function, as you can
see in cells E3 and E4
=SUM(NumList) or =SUM(NumListDyn)

Instead of typing the name in the SUM formula, you can refer to the range name in a worksheet cell. For
example, with the name NumList in cell D7, the formula in cell E7 is:
=SUM(INDIRECT(D7))
Unfortunately, the INDIRECT function can't resolve a dynamic range, so when the formula is copied down
to cell E8, the result is a #REF! error.

66

Example 3: Create reference from sheet, row, column info


You can easily create a reference based on row and column numbers, by using FALSE as the second
argument in the INDIRECT function. This creates an R1C1 style reference, and in this example, a sheet
name is also included -- 'MyLinks'!R2C2
=INDIRECT("'" & B3 & "'!R" & C3 & "C" & D3,FALSE)

Example 4: Create array of numbers that doesn't shift

In some formulas, you need an array of numbers, as in this example, where we want the average of the 3
highest numbers in column B. The numbers could be typed in the formula, as they are in cell D4:
=AVERAGE(LARGE(B1:B8,{1,2,3}))
If you need a bigger array of numbers, you probably wouldn't want to type all of them. Another option is to
use the ROW function, as in the array-entered formula in cell D5:
=AVERAGE(LARGE(B1:B8,ROW(1:3)))

67

A third option is to use the ROW function with INDIRECT, as in the


formula in cell D6, which is also array-entered:
=AVERAGE(LARGE(B1:B8,ROW(INDIRECT("1:3"))))
The results for all 3 formulas are the same.

However, if rows are inserted at the top of the sheet, the second formula returns an incorrect result,
because the rows are adjusted. Now, instead of the average of the top 3 numbers, it shows the average of
the 3rd, 4th and 5th largest numbers.
With the INDIRECT function, the third formula keeps the correct row reference, and continues to show the
correct result.

68

69

DATA ANALYSIS

70

How to Set up Your Data for Easy Sorting and Subtotals


The essential beauty of Excel is that you can make calculations and analyze/manipulate data quickly and
easily on the fly! What-if analysis is easy in Excel. You can Sort to see which Sales Rep had the greatest
sales, create Subtotals by Region, and do complex data analysis such as summarizing on multiple criteria
(PivotTables). (This section is only a brief look at Excels infinite Analyzing capabilities). For this section we
will look at Sorting, Filtering, automatic Subtotals and a basic PivotTable.
The #1 MOST IMPORTANT THING TO REMEMBER WHEN YOU START TO USE EXCELS DATA ANALYSIS
TOOLS IS:
Before you use Excels Data Analysis Tools: the data must be in proper Excel List or Table Format. This
format is as follows: 1) First row has field names with formatting that is different from the rest of the data;
2) No blank field names; 3) Columns are called Fields; 4) Rows are called records; 5) No blank columns
(fields); 6) No blank rows (records); 7) Blank rows and columns and/or Excels column headers (A, B)
and/or row headers (1, 2) must separate the Excel List from other data
Columns are called Fields. Fields are the variable data for each record. Rows are called Records.
Records are individual collections of the fields. For example, navigate to the sheet tab named Analyze
Data, click on the Data Ribbon. You should see this Note: your data may not be in the same order as the
picture.

1. Proper Excel List or Table Format, which will refer to as Excels List/Table format (this is
because in Excel 2003 it was called List and in Excel 2007 it is called Table)
2. Each row represents one Sales Transaction
i. Each sales transaction is one new record
ii. Each record is an individual collection of the seven fields
3. The first seven columns represent fields
71

i. Each field is a variable


1. For each new transaction it can have a
different date or different region or different sales rep, etc.

72

How to Sort Data


Steps to Sort on various criteria
1. The method of sorting we will look at involves turning on the Filter with the keyboard
shortcut for Filter: hold Ctrl and Shift, then tap the L key. In Figure 325 you can see that that
keyboard short cut added drop-down arrows at the top of each field and turned on the Filter
button in the Sort and Filter Group on the Data Ribbon.

2. Point to the drop-down arrow for the Sales field and point to Sort Largest to Smallest

3. As seen, instantly, the whole table is sorted by the sales numbers in the Sales field. We can
easily see that Sales Rep Luke had the two largest sales.

73

4. Next click on the drop-down arrow for the Sales Rep field and
click on the Sort A to Z from the drop-down list

5. As seen, instantly, the whole table is sorted by the names in the Sales Rep field, with Chin at the
top.

6. To see how to sort without the Filter turned on, turn off the Filter with the keyboard shortcut
Ctrl + Shift + L, then click in cell B6.

7. With only one cell selected in the Region field column, click the A Z icon button in the Sort
& Filter Group on the Data Ribbon.

74

8. As seen, the whole table was sorted by the region names in


the Region field column.
9. Now take a moment and think about what we just did in the last 8 steps. What we did was to
sort three different fields (columns) in succession. Anytime you do this, each subsequent sort
remembers the sort from before. If you look at Error! Reference source not found. notice that
he Region column is sorted, but within Region, the Sales Rep column is also sorted: we can see
that all of Chins MidWest sales have been brought together with our sorting action. But wait,
we did three sorts:
you can see that all of Chins largest sales for the MidWest have been brought up to the top of
the data set. This is a convenient end-result of the Sorting feature. The terminology associated
with this kind of sorting action is that we call that last column to be sorted the Major Sort, and
you would describe the whole process by saying We sorted the Sales field within the Sales Rep
field within the Region field.

NOTE: Before click the A Z icon button in the Sort & Filter Group on the Data Ribbon, make sure your
block of data is in the Proper Excel List/Table Format and highlight only one cell in the field you want to
sort.

75

Quickly Filter a List to Certain Records


Steps to filter your data
1. Navigate to the sheet named Filter. You can use this keyboard shortcut to move down two
sheets: Hold Ctrl and then tap the Page Down key twice. You should see the data as seen. Then,
turn on the Filter using the keyboard shortcut: Ctrl + Shift + L

Hold Ctrl and Shift


at the same time
and then tap L
to turn on the
Filter

76

2. To see the Sales that are Above Average,


click the drop-down arrow at the top of the
Sales field and in the drop down list point to
Number Filters and then point and click on
Above Average.

3. As you
can see in Figure 334 Excel quickly shows us
the results. Notice two things:
1) The drop-down arrow at the top of the
Sales field contains a Filter icon to let us
know that the field has been filtered;
2) The row numbers are the color blue to let
you know that the rows with records that
are not above average have been hidden.
For example, you can see that rows 2 and 3
are hidden.

4. To clear the filter, click on the drop-down


arrow at the top of the Sales field and click
on the item Clear Filter From Sales.

5. To see a brief example of the options


available for filtering words, click on the
drop-down arrow at the top of the
Customers fields and point to Text Filters.
Notice that you can uncheck any customers
you would like if you only want to see a
selection of Customers. In addition, you can
see the Text Filters available.

77

6. Next we want to see how to sort by


color.That the color yellow is added to
some of the dates. This color was to tag
those records for auditing. Instead of
scrolling down and seeing each record one
at a time, we can sort by color.

9. As you can see to our brief introduction to


Sorting and Filtering, it allows us to do data
analysis efficiently. In addition, you can also
see from some of the drop down menus
that we only looked at a small fraction of
the possibilities!
In our next section, we will look at another data
analysis tool: Subtotals.

NOTE: Using the Sorting or Filtering features in


Excel can save a tremendous amount of time as
compared to accomplishing the same sorting or
filtering tasks manually.
7. Click on the drop-down arrow at the top of
the Date fields and point to Sort by Color
and then click on the color yellow:

8. We can see that very quickly our records


that we need for auditing are sorted to the
top.

78

Add Subtotals to a Data set


Steps to add automatic Subtotals
1. Before we look at Subtotals, navigate back to the sheet tab named Data Analysis.

2. Subtotals are one of the greatest tricks in Excel because using the Subtotal feature quickly goes
through the whole table and inserts rows and adds totals for the column that you specify. In our
case, we will be able to very quickly add totals for all the regions and Sales Reps!
3. An important point to make here is this: DONT USE THE SUBTOTALS FEATURE FOR A PARTICULAR
FIELD UNTIL YOU HAVE SORTED THAT FIELD.
4. We have already sorted the region and the Sales Rep fields so that we can use the Subtotal feature.
5. As seen in Figure 341, click on the Subtotalsicon button in the Outline Group on the Data Ribbon.

6. You should see Subtotal dialog box as seen. Notice that the whole table was highlighted when you
invoked the Subtotals dialog box (this is because you have your data in proper Excel List/Table
format). Using the drop-down arrow for the At each change in textbox, select the Region field.
For the Use function:, use the Sum function. For the Add subtotals to: checkboxes check the
Sales field.

79

80

8. Click OK. You should see something similar to the Figure. On the
left of your screen you should see three little blue-gray boxes with the numbers 1, 2, and 3 in them.
These are called Outline buttons.

9. Click the 2 Outline button and you should see subtotals similar to those as seen. The plus and
minus symbols are collapse and expand symbols. You can use these to expose the data for a
particular Region. You can also use the 3 Outline button to expose all the records. Before you
click on the 3 Outline button, notice that there are 200 rows of sales transaction data that the
Subtotals feature traversed in less than a second! This is an amazingly efficient feature in Excel!

The Subtotal feature works through 200 rows of data quickly

10. Click on the 3 Outline button to show all the records again:

11. Open the Subtotals dialog box with the


keyboard shortcut: Alt + A + B. As seen
in the Figure, use the drop-down arrow
next to the At each change in textbox
to select the Sales Rep field. For the
Use function: use the Sum function.
For the Add subtotals to: checkboxes
check the Sales field. Finally (this is the
most important step when adding a
second Subtotal), un-check the Replace
current subtotals checkbox and then
click OK.
81

82

12. As seen in the Figure, a fourth Outline Level has been added.

13. Click on the 3 Outline button. As seen in the Figure, Subtotals have been added for both the
Region and Sales Rep fields. With this Subtotal Data Analysis, we can easily pick how each Sales Rep
did in each Region.

14. To get rid of the Subtotals, use the keyboard shortcut to open the Subtotals dialog box: Alt + A + B
and then click the Remove All Button

15. In our next section we will talk about the most powerful toll in Excel, the PivotTable.
NOTE: Before adding automatic Subtotals, sort your field. If you want to add a Subtotal to a Subtotal, Be
sure to uncheck theReplace current subtotals check box.
83

Use a Pivot Table to Summarize Detailed Data


Steps to create a Basic PivotTable
1. What is a PivotTable? It is a quick way to analyze data such as summing up data in a rectangular
table shape when you have more than one category to summarize upon. The Figure shows us an
example of what would like to accomplish from our data. As you can see we have two categories
(Sales Rep and Region) and we have a rectangular table shape. To create this without using the
PivotTable feature, but instead to use functions would be very time consuming.

Chin
Jeri
Jon
Luke
Rhonda
Sheliadawn
Steven
Troung
Grand Total

West
161,464.09
290,770.33
173,559.67
210,096.98
185,281.95
188,710.09
189,088.14
170,702.25
1,569,673.50

MidWest
247,987.69
207,164.71
231,778.99
199,211.40
192,855.38
185,465.42
165,974.78
221,063.19
1,651,501.56

North
257,832.05
169,784.64
258,672.84
231,024.41
156,087.13
169,710.11
235,576.52
227,730.44
1,706,418.14

NorthEast
486,840.62
424,234.18
334,794.87
333,815.59
402,080.39
520,169.79
500,920.09
423,634.06
3,426,489.59

SouthEast
255,416.43
220,679.39
277,404.03
208,200.24
167,137.03
156,876.25
204,597.69
233,110.32
1,723,421.38

Grand Total
1,409,540.88
1,312,633.25
1,276,210.40
1,182,348.62
1,103,441.88
1,220,931.66
1,296,157.22
1,276,240.26
10,077,504.17

2. To create something similar to what we see in Figure, make sure you have one cell in your data
table selected and that your data is in proper Excel List/Tableformat, then click on the PivotTable
icon button in the Table group on the Insert Ribbon:

84

4. Notice that because we are using proper Excel List/Table format


and we had selected one cell in the middle of our data, all the data was automatically selected. As
we can see in Figure 351 Create PivotTable dialog box opens and we can see that the range
A1:G2000 is selected. In addition, we want to create our PivotTable on a new sheet and so we will
accept the defaults and then click the OK button.

5. In Figure we can see that the PivotTable Field List Task Pane pops up and a new sheet is added to
the workbook. All we have to do in order to create a table with the two categories Sales Rep and
Region is to click on the checkboxes for those two fields (after all this is just field list).

PivotTable Field List


Task Pane

85

6.
As seen in Figure, by checking the two
fields, both were added as Row Labels.

Click on
the
Region
field and
drag it to
the
Column
Labels
area

7.
As seen
in Figure, because we want the Sales Rep field as a
Row Label and our Region as a Column Label, we
will click on the Region field in the Row Labels
area, hold the click, and drag it to the Column
Labels area

8.
As seen in Figure, we have our two category
labels

86

9.
As seen in Figure , we can see our PivotTable taking shape. We can
see that the Sales Rep labels and the Region labels in our worksheet. We can see that two context-sensitive
Ribbons for the PivotTable have appeared (PivotTable Tools Options and Design Ribbons).

We can see that


the Sales Rep
labels and the
Region labels in
our worksheet.

We can see that two


context-sensitive
Ribbons for the
PivotTable have
appeared.

10.
Next, as seen in Figure, click on the Sales field in the PivotTable Field List Task Pane this adds the
Sales field to the Values area. PivotTables use the Sum Function by default, which is what we wanted in our
case. To see how to change the function and to format the Sales numbers, click the close x button in the
top right corner of the PivotTable Field List Task Pane and then click in cell A3.

11.

With your cursor in cell A3, right-click and point to Value Field Settings:

87

12.
As seen in Figure, the Value Field Settings dialog box should appear: If you were to change the
function, you could do so in the Summarize value field by function list. Because we want to change the
Number formatting, we will click the Number Format button.
If you were to change the function, you
could do so in the Summarize value field
by function list.

Number Formatting

88

14.
This is another one of those situations when two dialog boxes are
opened. When the Format Cells dialog box appears, select the Currency Number format. Then click the OK
button on the Format Cells dialog box. Then click the OK button on the Value Field Settings dialog box.

15.
With only a few clicks, the PivotTable is done. Even better than with Subtotals, we can easily see
how each Sales Rep did in each Region:

89

STREAMLINING
WORKFLOW

90

Apply Conditional Formatting


What is Conditional Formatting?
With conditional formatting, you can select one or more cells, and create rules (conditions) for when and
how those cells are formatted. The conditions can be, based on the selected cell's contents, or based on the
contents of another cell.
You can control the following formats:

Number format
Font, font style, and font colour (but not font size)
Fill colour and fill pattern
Border colour and border style (but not border thickness)

If the rules (conditions) that you specified are met, then the formatting is applied.
For example, you can set conditional formatting so that a cell turns red if its value is low, and turns green if
its value is high.

Apply Conditional Formatting to a Cell


In this example, you'll set conditional formats so that a cell:

turns green if it contains a value higher than 75 and


turns red if it contains a value lower than 50.

Follow these steps to apply conditional formatting to cells:


1. In cell I2, type the high value -- 75
2. In cell I2, type the low value -- 50
91

3. Select the cells to be formatted. In this example, cells E2:E7 are selected.
4. On the Ribbon's Home tab, click Conditional Formatting

5. To format the high values, click Highlight Cell Rules, then click Greater Than...

6. In the Greater Than window, delete the value that appears, and click on cell I1, where the High
value is entered.

92

7. Click the drop down list for formats, and click Custom Format.

8. In the Format Cells window, click the Fill tab, and click on the green fill color that you want.

9. Click OK to close the Format Cells window, and click OK to close the Greater Than window.
The cells with values greater than 75 are now coloured green.

93

Apply 2nd Conditional Format


To color the low values in red fill, you can apply a second condtional formatting rule to the cells.
1. Select the cells to be formatted. In this example, cells E2:E7 are selected.
2. On the Ribbon's Home tab, click Conditional Formatting

3. To format the high values, click Highlight Cell Rules, then click Less Than...

4. In the Less Than window, delete the value that appears, and click on cell I2, where the Low value is
entered.

5. Click the drop down list for formats, and click Custom Format.

94

6. In the Format Cells window, click the Fill tab, and click on the green fill colour that you want.

7. Click OK to close the Format Cells window, and click OK to close the Less Than window.
The cells with values greater than 75 are now coloured green, and cells less than 50 are red.

95

Advanced Filter
Apply an Excel Advanced Filter
Set up the database
1.
2.
3.
4.

The first row (A1:D1) has headings.


Subsequent rows contain data.
There are no blank rows within the database.
There is a blank row at the end of the database, and a blank column at the right.

2. Set up the Criteria Range (optional)


In the criteria range for an Excel advanced filter, you can set the rules for the data that should remain
visible after the filter is applied. You can use one criterion, or several.
1. In this example, cells F1:F2 are the criteria range.
2. The heading in F1 exactly matches a heading (D1) in the database.
3. Cell F2 contains the criterion. The > (greater than) operator is used, with the number 500 (no $ sign
is included)..
After the Excel advanced filter is applied, orders with a total greater than $500 will remain visible.

Other operators include:


< less than
<= less than or equal to
>= greater than or equal to
<> not equal to
96

3. Set up the Extract Range (optional)


If you plan to copy the data to another location, you can specify the columns that you want to extract. If
you want to extract ALL columns, you can leave the extract range empty for the Excel advanced filter.
1. Select the cell at the top left of the range for the extracted data.
2. Type the headings for the columns that you want to extract. These must be an exact match for the
column headings, in spelling and punctuation. The column order can be different, and any or all of
columns can be included

4. Apply the Excel Advanced Filter


1. Select a cell in the database.
2. On the Excel Ribbon's Data tab, click Advanced, to open the Advanced Filter dialog box

3.
4.
5.
6.

You can choose to filter the list in place, or copy the results to another location.
Excel should automatically detect the list range. If not, you can select the cells on the worksheet.
Select the criteria range on the worksheet
If you are copying to a new location, select a starting cell for the copy
Note: If you copy to another location, all cells below the extract range will be cleared when the
Advanced Filter is applied.
7. Click OK

97

Filter Unique Records


You can use an Excel Advanced Filter to extract a list of unique items in the database. For example, get a list
of customers from an order list, or compile a list of products sold. In this example, the unique list is copied
to a different location and the original list in unchanged.
Note: The list must contain a heading, or the first item may be duplicated in the results.
1.
2.
3.
4.
5.
6.
7.
8.

Select a cell in the database.


On the Excel Ribbon's Data tab, click Advanced.
In the Advanced Filter dialog box, choose 'Copy to another location'.
For the List range, select the column(s) from which you want to extract the unique values.
Leave the Criteria Range blank.
Select a starting cell for the Copy to location.
Add a check mark to the Unique records only box.
Click OK.

98

Extract Data to another Worksheet


If the database is on one sheet, you can extract data to a different sheet, by using an Excel Advanced Filter.
In this example, the data is on Sheet1, and will be copied to Sheet2.
1. Go to Sheet2
2. Select a cell in an unused part of the sheet (cell C4 in this example).
3. On the Excel Ribbon's Data tab, click Advanced
4. Choose Copy to another location.
5. Click in the List Range box
6. Select Sheet1, and select the database.
7. (optional) Click in the Criteria range box.
8. Select the criteria range
9. Click in the Copy to box.
10. Select the cell on Sheet2 in which you want the results to start, or select the headings that you have
typed on Sheet2.
11. (optional) Check the box for Unique Values Only
12. Click OK

99

Setting up the Excel Advanced Filter Criteria Range


AND vs OR
If a record meets all criteria on one row in the criteria area, it will pass through the Excel
advanced filter. In example 1, at right -

the customer must be MegaMart


AND the product must be Cookies
AND the total must be greater than 500.

Criteria on different rows are joined with an OR operator. In the second example at right -

the customer must be MegaMart


OR the product must be Cookies
OR the total must be greater than 500.

By using multiple rows, you can combine the AND and OR operators. In the third example at right -

the customer must be MegaMart AND the product must be Cookies


OR
the product must be Cookies AND the total must be greater than 500.

Using Wildcards in Criteria


Use wildcard characters to filter for a text string in a cell.
100

The * wildcard
The asterisk (*) wildcard character represents any number of characters in that position,
including zero characters.
In this example, any customer whose name contains "mart" will pass through the Excel advanced
filter.

The ? wildcard
The question mark (?) wildcard character represents one characters in that position.
In this example any 4-letter product that begins with c, and ends with ke, will pass through the Excel
advanced filter. Both Coke and Cake are in the filtered results.

The ~ wildcard
The tilde (~) wildcard character lets you search for characters that are used as wildcards.
In the first example at right, an asterisk is in the criteria cell -- Good*Eats -- so any products that begins
with Good and ends with Eats, will pass through the Excel advanced filter.
To find only the product that is named Good*Eats, use a tilde character in front of the asterisk in the
critereia cell. -- Good~*Eats.

101

Excel Advanced Filter Criteria Examples


Extract Items in a Range
To extract a list of items in a range, you can use two columns for one of the fields. In this example, two
columns are used for the Date field.
If you enter two criteria on the same row in the criteria range, you create an AND statement. In this
example, any records that are extracted must be greater than or equal to the first date AND less than or
equal to the second date.

Create Two or More Sets of Conditions


If you enter criteria on different rows in the criteria range, you create an OR statement.
In this example, extracted records must meet both conditions in row 2 OR both conditions in row 3.
In the results, only the records for MegaMart Cookies, or for MiniMart Milk will be in the filter results.

102

Extract Items with Specific Text


When you use text as criteria with an Excel advanced filter, Excel finds all items that begin with that text.
For example, if you type "Ice" as a criterion, Excel finds "Ice", "Ice Cream" and "Ice Milk"
To extract only the records for Ice, use the following format:
="=Ice"

103

Record and Test Macro


What Can Excel Do Without Macros?
Excel can do all kinds of amazing things, without macros. Get to know Excel's powerful built-in features,
such as:

Conditional Formatting
Data Validation
Pivot Tables
AutoFilters and Advanced Filters

If you use those built-in features, you might not need a macro. For example, instead of checking each cell in
a column, and manually coloring the cell green if it's over 50, use conditional formatting to highlight the
cells automatically.

Identify an Excel Task to Automate


If you use Excel every day, you probably have a few tasks that you repeat daily, weekly or monthly. To get
started with Excel VBA, you could focus on one of those tasks, and try to automate it.
Every day, in your imaginary job, you open that Orders file and filter the list of orders, to find all the orders
for binders. Then you copy the orders, and paste them into a new workbook.
Here's a summary of the steps that you follow every morning:
1.
2.
3.
4.
5.

Open the orders file


Filter the list for binder orders
Copy the binder orders
Create a new workbook
Paste the binder orders into the new workbook.

Instead of doing that task manually every day, you could automate it, by creating an Excel macro.

104

Get Ready to Record


Now that you've decided to automate this task, you'll use Excel's Macro Recorder tool to create the Excel
VBA code. Before you start recording, you'll get everything into position. For example:

Do you want the macro to open a specific workbook, or will that workbook already be open?
Should you select a cell or worksheet before the macro runs, or will selecting the cell be part of the
macro?

In this example, you want the macro to open the Orders workbook for you, and then filter and copy the
data. So, the Orders workbook should be closed when you start recording. You don't need to select a
specific cell or worksheet before recording; any cell selection will be done during the macro recording.
Start Recording
Once everything is in position, you can get ready to start recording.
1. Open a new blank workbook, which is where you'll store the macro.
2. At the bottom left of the Excel window, click the Record Macro button.

3. In the Record Macro dialog box, type a one word name for the macro, CopyDailyRecords

4. From the Store Macro In drop down, select This Workbook as the workbook where you'd like to
store the VBA code. Later, you can open this workbook every morning, to run the macro.

105

5. In the Description box, you can type a brief note about what the macro will do. This is optional, and
you can leave the Description box empty, if you prefer.

6. Click OK, to start recording.


Perform the Macro Steps
While the Macro Recorder is on, you'll perform the steps that you want to automate. In this example, these
are the steps that you should do now:
1.
2.
3.
4.
5.

Open the orders file - Orders.xlsx


On the Data sheet in the Orders file, use an AutoFilter to view the binder orders
Copy the filtered binder orders, including the heading row.
Create a new blank workbook
Paste the binder orders into the new workbook, in cell A1 on Sheet1.
106

If you make a mistake - no problem! Just stop the recording (instructions below), close the files without
saving, and start over again.
Stop the Recording
Once you finished all the steps, follow these steps to turn off the Macro Recorder and save the macro file.
1. Click the Stop Recording button at the bottom left of the Excel window.

2. Close the workbook where you pasted the binder orders, without saving the changes.
3. Close the Orders.xlsx workbook, without saving the changes
4. Save the workbook where you stored the macro:
o Name: BinderCode.xlsm
o File Type: Excel Macro-Enabled Workbook *.xlsm
5. Close the BinderCode.xlsm file.
Get Ready to Test the Macro
To prepare to test the macro, make sure that the Orders.xlsx workbook is closed.
Add the Developer Tab
To run the macro, you'll use the Developer tab on the Excel Ribbon. You can add the Developer tab to the
Excel Ribbon, if it's not there already.
To add the Developer tab in Excel 2010:
1. Right-click on the Ribbon, and click Customize Ribbon
2. Add a check mark beside Developer, in the list at the right.
3. Click OK, to close the Excel Options window.
To add the Developer tab in Excel 2007:
1. Click the Microsoft Office Button, and then click Excel Options.
2. Click the Popular category, and add a check mark to Show Developer tab in the Ribbon
107

3. Click OK, to close the Excel Options window.

Macro Security Settings


If you haven't run macros before, you might need to change your macro security level. (You may have to
clear this with your IT department.)
1.
2.
3.
4.

On the Ribbon, click the Developer tab, and in the Code group, click Macro Security.
In the Macro Settings category, under Macro Settings, click Disable all macros with notification
Click OK.
If you changed the setting, close the workbook, and then reopen it.

Test the Macro


Now that the Developer tab is visible, you can get ready to test the macro. Open the Macro File First you'll
open the file where the recorded macro is stored, and enable macros, by following these steps:
1. Open the file (BinderCode.xlsm) where you stored the macro that you recorded.
2. If a security warning appears at the top of the worksheet, click the Options button.

3. Click Enable This Content, to allow the workbook's macros to run, and click OK.

108

Run the Recorded Macro


Now, follow these steps to run the macro, to see if it works the way you want.
1. On the Ribbon, click the Developer tab, and in the Code group, click Macros.

2. In the Macro dialog box, click the macro that you want to run - CopyDailyRecords.
3. Click Run.

If you see an error message, click the End button, and try recording the macro again. If everything went as
expected, great! You can close all 3 workbooks used by the macro, without saving the changes.

109

Anda mungkin juga menyukai