Advanced Excel Manual
Advanced Excel Manual
Microsoft®
Student Edition
Level 3 - Advanced
A.J.Silicon
TABLE OF CONTENT
INTRODUCTION ................................................................................................................................................................5
How to Use the Lessons .......................................................................................................................................................6
Lesson 1-6: Using the PMT Function ...................................................................................................................................9
Financial Functions............................................................................................................................................................. 11
Date and Time Functions ....................................................................................................................................................13
Statistical Functions ............................................................................................................................................................15
Database Functions .............................................................................................................................................................16
Lesson 2-7: Filtering a List with the AutoFilter ..................................................................................................................17
Lesson 2-8: Creating a Custom AutoFilter .........................................................................................................................19
Lesson 2-9: Filtering a List with an Advanced Filter..........................................................................................................21
Lesson 2-10: Copying Filtered Records .............................................................................................................................23
Lesson 2-11: Using Data Validation ...................................................................................................................................25
5 | A D VA N C E E X C E L
How to Use the Lessons
Every topic is presented on two facing pages, so that you can concentrate on the lesson without having to worry about
turning the page. Since this is a hands-on course, each lesson contains an exercise with step-by-step instructions for you
to follow.
To make learning easier, every exercise follows certain conventions:
Anything you‘re supposed to click, drag, or press appears like this.
Anything you‘re supposed to type appears like this.
This book never assumes you know where (or what) something is. The first time you‘re told to click something, a
picture of what you‘re supposed to click appears either in the margin next to the step or in the illustrations at the
beginning of the lesson.
In this lesson, you will learn how to apply number formats. Applying number formatting changes
You can also format howIn values are displayed—it
this lesson, you will learn doesn‘t
how tochange
apply the actual
number information
formats. in any
Applying way. Excel
number is often
formatting changes
Tips and traps appear in the values
You by
canusing the
also format smart
howenough
values to
areapply some number
displayed—it doesn‘t change the
formatting actual information
automatically. in anyifway.
For example, youExcel is often
use a dollar
Formatting
values by toolbar
using the sign to indicate
smart enoughcurrency
to apply (such
some as $548.67),
number Excel will
formatting automatically
automatically. Forapply the currency
example, if you usenumber
a dollar
margin. or Formatting
by selectingtoolbar format
sign for you. currency (such as $548.67), Excel will automatically apply the currency number
to indicate
Format
or by Cells
selecting format for you.
The Formatting toolbar has five buttons (Currency, Percent, Comma, Increase Decimal, and
from the menu
Format and
Cells The Formatting
Decrease Decimal)toolbar
you canhas usefive buttons apply
to quickly (Currency,
commonPercent, Comma,
number Increase
formats. If none Decimal,
of theseandbuttons
clicking
from the menu and
Number tab. hasDecrease
what you‘re looking
Decimal) you for,
can you
useneed to use the
to quickly applyFormat Cellsnumber
common dialog formats. If none of
box by selecting these
Format buttons
clicking the
Icons and pictures appear in the Number tab. hasfrom
Cells
dialog
whatthe
Cellsbox
you‘re
menulooking
isn‘t
from theasmenu
fast as
and
for, you
and clicking
using
theneed
the toolbar,
clicking
to usetab.
Number theFormatting
Format Cells
but ittab.
the Number gives
dialog with
numbers
you morenumbers
Formatting
box bytheselecting
precisionwith
and the
Format
Format Cells
Format Cells
formatting options.
margin, showing you what to dialog
We‘ll usebox
bothisn‘t as fastinasthis
methods using the toolbar, but it gives you more precision and formatting options.
lesson.
We‘ll use both methods in this lesson.
click or look for. 1. Select the cell range D5:D17 and click the Comma Style button on
Comma Style 1.theSelect the celltoolbar.
Formatting range D5:D17 and click the Comma Style button on
Comma
buttonStyle theadds
Excel Formatting toolbar.(the comma) and two decimal places to the selected cell
a hundreds separator
button range.
Excel adds a hundreds separator (the comma) and two decimal places to the selected cell
Clear step-by-step instructions range.
6 | A D VA N C E E X C E L
When you see a keyboard instruction like ―press <Ctrl> + <B>,‖ you should press and hold the first key (<Ctrl> in
this example) while you press the second key (<B> in this example). Then, after you‘ve pressed both keys, you can
release them.
There is usually more than one way to do something in Excel. The exercise explains the most common method of
doing something, while the alternate methods appear in the margin. Use whatever approach feels most comfortable
for you.
Important terms appear in italics the first time they‘re presented.
Whenever something is especially difficult or can easily go wrong, you‘ll see a:
NOTE:
immediately after the step, warning you of pitfalls that you could encounter if you‘re not careful.
Our exclusive Quick Reference box appears at the end of every lesson. You can use it to review the skills you‘ve
learned in the lesson and as a handy reference—when you need to know how to do something fast and don‘t need to
step through the sample exercises.
Formatting a Worksheet 25
Formatting a Worksheet 25
7 | A D VA N C E E X C E L
Lesson 1-1: Using the PMT Function
Figure 0-1
The Insert Function dialog
box
Figure 0-2
The Function Arguments
dialog box
Figure 0-3
The PMT function is a very valuable function if you work with real estate, investments, or are considering taking out a loan.
The PMT function calculates the payment for a loan based on periodic payments and a constant interest rate. For example, say
you want to take out a $10,000 car loan at 8% interest and will pay the loan off in four years. You can use the PMT function
to calculate that the monthly payments for such a loan would be $244.13.You can also use the PMT function to determine
payments to annuities or investments. For example, if you want to save $50,000 in 20 years by saving the same amount each
month, you can use PMT to determine how much you must save.
If you do not know where your practice files are located, ask your instructor for assistance. All of the information you
need to find the monthly payments has already been entered. All you have to do is use the PMT function to calculate the
monthly payment. The PMT function is a little complicated, so use the Insert Function feature to help you enter it.
2. Click cell D4 and click the Insert Function button on the Formula bar.
3. Select Financial from the Or select a category list, scroll down the Select a Function list, select
PMT, and then click OK.
The Function Arguments dialog box appears, as shown in Figure 0-2. You‘re ready to start entering the PMT formula to
calculate the monthly mortgage payments. Look at Figure 0-2: the first argument of the PMT function is the interest
rate. Since the Function Arguments dialog box is in the way, you‘ll have to click the Collapse Dialog button to see and
reference the cells on the worksheet.
4. Click the Rate Collapse Dialog Box button, click cell C4, and press <Enter>.
Because you want to calculate monthly payments instead of annual payments, you will need to divide
the annual interest rates by 12.
Collapse Dialog
5. Type /12 to divide the annual interest rate. Box button
C4/12 should appear in the Rate text box. The next argument in the PMT function is the Nper—the total number of
payments for the loan.
9 | A D VA N C E E X C E L
6. Click the Nper box and type B4*12.
Again, you want to calculate monthly payments so you need to multiply the total number of years by 12. The
last step in the PMT formula is entering the Pv—the principal.
Enter button
7. Click the Pv Collapse Dialog Box button, click cell A4, and press <Enter>.
You‘re finished entering the PMT formula so you can close the Function Arguments dialog box.
8. Click OK.
The Function Arguments dialog box closes, and the monthly payment, ($1,162.95), appears in cell D4.
Hey! Why does the monthly payment appear red (a negative number)? It‘s because the PMT formula shows the
borrower‘s point of view, and therefore the payments are calculated as a negative cash flow. You can easily change the
formula so that it shows a positive number by editing the formula and placing a minus sign in front of the Pv value.
9. Edit the formula in cell D4 by clicking the Formula bar, and adding a
- (minus sign) immediately after the = sign, so that the formula reads
=-PMT(C4/12,B4*12,A4), then click the Enter button on the Formula bar.
The PMT formula now displays the monthly payments as a positive number. Copy the formula to find the monthly
payments for the other loans.
10. Copy the formula you just created to the cell range D4:D6.
The PMT formula is copied. Cell D5 displays a monthly payment of $1,208.39 and cell D6 displays a monthly payment
of $1,048.82. Now that you have calculated the monthly payments for each of the three loans, you can easily calculate
even more information, such as the total interest paid and total amount paid on each loan.
11. Click cell E4, type =, click cell D4, type *, click cell B4, type *12, so that the formula reads
=D4*B4*12, and click the Enter button on the Formula bar.
Now that you know the total amount of all the loan payments, you can find how much the total interest will be.
12. Click cell F4, type =, click cell E4, type -, click cell A4 and click the Enter button on the Formula
bar.
Wow! That interest really adds up, doesn‘t it?
13. Copy the formula in cell E4 into cells E5:E6. Copy the formula in cell F4 into cells F5:F6. Compare
your workbook with the one in Figure 0-4.
Try experimenting with different loan amounts, interest rates, and loan lengths for the different loans.
10 | A D V A N C E E X C E L
Financial Functions
Excel‘s financial functions are vital if you work with investments or real estate. Financial functions help determine loan
payment amounts, calculate the future value of investments, and find rates of return.
NPV =NPV(rate, value1, Calculates the net present value of an investment by using
value2, ...) a discount rate and a series of future payments (negative
values) and income (positive values).
PMT =PMT(rate, number of Calculates the payment for a loan based on constant
periods, present value, payments and a constant interest rate.
future value*, type*)
Example: The following formula calculates the monthly
payment on a $20,000 loan with an annual interest rate of
9% that must be paid in 36-months.
PMT(9%/12, 36, 20000) equals ($635.99)
PV =PV(rate, number of Returns the present value of an investment.
periods, payment, future Example: An annuity that pays $600 every month for the
value*, type*) next 20 years costs $50,000, and the money paid out will
earn 7 %. You want to determine whether this would be a
good investment. Using the PV function, you find that the
present value of the annuity is:
PV(0.07/12, 12*20, 600, , 0) equals ($77,389.50)
11 | A D V A N C E E X C E L
Function Syntax Description
RATE =RATE(total number of Determines the interest rate per period of an annuity.
payments, payment,
present value) Example: You want to calculate the rate of a four-year (48
month) $8,000 loan with monthly payments of $200. Using
the RATE function you find:
RATE(48, -200, 8000) equals 0.77 percent
This is the monthly rate, because the period is monthly.
The annual rate is 0.77%*12, which equals 9.24 percent.
* Optional arguments.
12 | A D V A N C E E X C E L
Date and Time Functions
You can use dates and time in your formulas just like any other value. For example, if cell A1 contained the entry 5/1/99 you
could use the formula =A1+100 to calculate the date 100 days later, which is 8/9/99.
One very important thing to know about working with date and time functions: while Excel can display dates and times using
just about any format, it actually stores dates as chronological numbers called serial values. So when you think of dates as
months, days, and, years, such as May 1, 1999, Excel thinks of dates in terms of serial numbers, such as 36281.
NOTE: Since the following date and time formulas often return serial number values, you should format any cells with
date or time formulas with data and time formats that you can easily understand. You can also create custom
number formats to display the results of date formulas. For example, the custom format dddd would display
only the day, Monday, instead of the entire date, 8/9/99.
13 | A D V A N C E E X C E L
Function Syntax Description
MINUTE =MINUTE Returns the minute value for a specific time. The
(serial_number) serial_number argument is a time value (or reference to
one). Uses a 24-hour time format.
Example: MINUTE("12:15:45”) equals 15.
SECOND =SECOND Returns a value of a second for a specific time. The
(serial_number) serial_number argument is a time value (or reference to
one). Uses a 24-hour time format.
Example: SECOND("12:15:45”) equals 45.
HOUR =HOUR(number, Calculates the number of possible combinations from a
number_chosen) given number of items.
Example: You want to form a two-person team from five
candidates, and you want to know how many possible
teams can be formed.
COMBIN(5, 2) equals 10 teams.
DAYS360 =DAYS360(start_date, Returns the number of days between two dates based
end_date) on a 360-day year (twelve 30-day months), which is
used in some accounting calculations.
Example: DAYS360("1/30/93", "2/1/93") equals 1
14 | A D V A N C E E X C E L
Statistical Functions
Excel offers a large number of functions to help you analyze statistical data. If they‘re not enough you can also use the
Analysis Toolpak, found under Tools Data Analysis.
Function Syntax Description
AVERAGE =AVERAGE(number1, Calculates the average, or arithmetic mean, of the
number2…) numbers in the range or arguments.
COUNT =COUNT(number1, Counts the number of cells that contain numbers, including
number2…) dates and formulas. Ignores all blank cells and cells that
contain text or errors.
COUNTIF =COUNTIF(range,criteria, Counts the cells only if they meet the specified criteria.
sum_range) Similar to SUMIF.
MAX =MAX(number1, Returns the largest value in a range.
number2…)
MEDIAN =MEDIAN(number1, Calculates the median of the numbers in the range or
number2…) arguments. The median is the number in the middle of a
set of numbers—half the numbers have values that are
greater than the median, and half have values that are
less.
MIN =MIN(number1, Returns the smallest value in a range.
number2…)
MODE =MODE(number1, Determines which value occurs most frequently in a set of
number2…) numbers.
STDEV =STDEV(number1, Estimates standard deviation based on a sample. The
number2…) standard deviation is a measure of how widely values are
dispersed from the average value.
STDEVP =STDEVP(number1, Estimates standard deviation based on an entire
number2…) population.
SUMIF =SUMIF(range,criteria, Adds the cells only if they meet the specified criteria.
sum_range)
Example: You want to total the cell range B1:B5 only if the
value in cellA1 is greater than 500.
SUMIF(A1,">500",B1:B5)
VAR =VAR(number1, Estimates variance based on a sample.
number2…)
VARP =VARP(number1, Estimates variance based on an entire population.
number2…)
15 | A D V A N C E E X C E L
Database Functions
Database functions return results based on filtered criteria. All the database functions use the same basic syntax
=Function(database, field, criteria). The arguments include:
Database: The cell range that makes up the list or database.
Field: Indicates which column is used in the function. You can refer to fields by their column
label enclosed with double quotation marks, such as "Name" or as a number that represents the
position of the column in the list: 1 for the first column, 2 for the second, and so on—not the
column heading numbers!
Using this criteria Criteria: Is a reference to the cell or cell range that specifies the criteria for the function. For
range (A1:A3) in a example, you might only want to total records from a certain region.
database function
would only calculate Function Syntax Description
records with New York
DAVERAGE =DAVERAGE(database, Find the average of values in a column in a list or
or Boston in the field, criteria)
Destination field.
database that match the criteria you specify.
DCOUNT =DCOUNT(database, Counts the number of cells that contain numbers from a
field, criteria) list or database that match the criteria you specify.
DGET =DGET(database, field, Extracts a single record from a database that matches the
criteria) criteria you specify.
DMAX =DMAX(database, field, Returns the largest value from a database that matches
criteria) the criteria you specify.
DMIN =DMIN(database, field, Returns the smallest value from a database that matches
criteria) the criteria you specify.
DSTDEV =DSTDEVP(database, Estimates standard deviation based on a sample. The
field, criteria) standard deviation is a measure of how widely values are
dispersed from the average value.
DSUM =DSUM(database, field, Adds the values in a column in a list or database that
criteria) match the criteria you specify.
DVAR =DVAR(database, field, Estimates variance based on a sample from selected list
criteria) or database entries.
16 | A D V A N C E E X C E L
Lesson 2-2: Filtering a List with the
AutoFilter
Figure 0-5
Using the AutoFilter on a
worksheet
Figure 0-6
A list filtered by AutoFilter
Sometimes, you may want to see only certain records in your lists. By filtering a list, you display only the
records that meet your criteria, and hide the records that do not. For example, you could filter a client list to
display only clients who live in California. There are several ways to filter your lists. In this lesson, you will
learn the fastest and easiest way to filter a list with Excel‘s nifty AutoFilter feature.
Due to the enhancements that Microsoft made to list functionality in Excel 2003, AutoFilter is enabled by
default whenever a group of cells is designated as a list. You may not always want this feature to be active, so
first let‘s learn how to turn it off.
1. If necessary, open the workbook named Lesson 2C and save it as Database List.
If you do not know where your practice files are located, ask your instructor for assistance. AutoFilter list
17 | A D V A N C E E X C E L
2. Make sure the active cell is located inside the list and select Data AutoFilter from the menu.
AutoFilter is turned off, all of the records are listed, and the AutoFilter arrows disappear from the right of the field
headings.
To turn AutoFilter back on, simply repeat step 2.
3. Make sure the active cell is located inside the list and select Data Filter AutoFilter from the
menu.
List arrows reappear to the right of each of the field names.
4. Click the City list arrow.
An AutoFilter list containing all the cities in the column appears beneath the City field.
5. Select Duluth from the AutoFilter list.
Excel filters the list so that only records that contain Duluth in the City field are displayed, as
shown in Figure 0-6. Notice the status bar indicates the number of records that matched the filter
and that the AutoFilter list arrow for the City field changes colors, indicating it is filtering the
worksheet. You can filter a list by more than one field at a time.
Number of 6. Click the Annual Trips list arrow and select 2 from the AutoFilter list.
Filtered Records
Excel narrows the filter so that only those records that contain Duluth in the City field and 2 in the Annual Trips field
are displayed. Notice that the colors of the AutoFilter list arrows for both the City field and Annual Trip field are
different colors, indicating they are filtering the worksheet. Here‘s how to remove the current filter criteria and display
all the records.
18 | A D V A N C E E X C E L
Lesson 2-3: Creating a Custom AutoFilter
Show the Top or Number of values
Bottom values. to display. Figure 0-7
The Top 10 AutoFilter
dialog box.
Select Items or
Percent to
Figure 0-8
display.
The Custom AutoFilter
dialog box.
Figure 0-7
Figure 0-8
In the previous lesson, you learned how to use the AutoFilter feature to filter records by selecting a single value for one or
more columns. When you need to filter using more complicated criteria, you have to use a Custom AutoFilter. Custom
AutoFilters are more difficult to set up and create than ordinary AutoFilters, but they‘re much more flexible and powerful.
Custom AutoFilter can filter records based on more than one value, such as clients in a list that live in California or Oregon
and can filter records based on ranges, such as clients with an income greater than $40,000.
This lesson explains how to create and use a Custom AutoFilter. First, though, we need to cover one more ordinary AutoFilter
topic—how to use the Top 10 option to filter records with the highest (top) or lowest (bottom) values in a list:
1. Click the Income list arrow and select (Top 10…) from the AutoFilter list.
The Top 10 AutoFilter dialog box appears, as shown in Figure 0-7.
3. Click the Income list arrow and select (All) from the AutoFilter list.
The filter is removed and all the records are displayed.
4. Click the City list arrow and select (Custom…) from the AutoFilter list.
The Custom AutoFilter dialog box appears, as shown in Figure 0-8.
5. Make sure equals appears in the City list, then click the top comparison list arrow (adjacent to the
equals option) and select Duluth.
In the next step, you‘ll specify that you want to filter any records from Two Harbors as well.
19 | A D V A N C E E X C E L
6. Click the Or option, click the bottom City list arrow and select equals, click the bottom
comparison list arrow and select Two Harbors.
Compare your dialog box to Figure 0-8. The custom AutoFilter will now display records in which the City field equals
Duluth or Two Harbors. This type of search criteria is called a Logical Condition. You could also specify the logical
condition criteria in a way so that only records from Duluth and those with incomes greater than $30,000 are filtered.
7. Click OK.
The dialog box closes, and only the records from the city of Duluth or Two Harbors are displayed.
Custom AutoFilters are much more flexible and powerful than ordinary AutoFilters, but they still have some limitations. For
example, you can‘t filter lists based on more than two values (such as clients from California, Oregon, or Washington). For
really complicated filtering tasks, you‘ll need to use an advanced filter, which is covered in the next lesson.
Quick Reference
To Use a Custom
AutoFilter:
1. Click one of the
drop-down list arrows in
the field names of the
header row and select
Custom from the list.
2. Specify your filter criteria
in the Custom AutoFilter
dialog box.
20 | A D V A N C E E X C E L
Lesson 2-4: Filtering a List with an Advanced
Filter
Copied column
Figure 0-9
heading labels
Creating the criteria range
for an advanced filter.
Criteria Figure 0-10
range
The Advanced Filter dialog
box.
List range
`
Figure 0-9
Figure 0-10
Advanced filtering is by far the most powerful and flexible way to filter your lists. It‘s also by far the most difficult method,
and requires more work to set up and use. Advanced Filters do have several capabilities their simpler AutoFilter cousins lack,
including:
More complex filtering criteria: You can filter a list based on as many values in as many columns as you want.
The ability to extract the filtered records: Once you have created an Advanced Filter, you can copy the filtered
records to a new location. This is the main reason most people use Advanced Filters.
To create an Advanced Filter you must start by defining a criteria range. A criteria range is a cell range, located at the top of
your list, which contains the filter criteria. Figure 0-9 shows an example of a worksheet with a criteria range.
1. Select rows 1 through 4, right-click any of the selected row number headings and select Insert
from the shortcut menu.
Excel inserts 4 blank rows above the list. These blank rows will be the Criteria Range—the cell range that contains a
set of search conditions you will use in your advanced filter. The next step in creating an Advanced Filter is to copy the
column labels from the list you want to filter.
2. Select the cell range A5:H5, click the Copy button on the Home Tab click cell A1, and click the
Paste button on the Home Tab to paste the copied cells.
Next, you need to specify the criteria for the advanced filter. You want to display only those clients with incomes
greater than $30,000 and that have taken more than five trips or those clients that have taken more than seven trips.
21 | A D V A N C E E X C E L
3. Click cell G2, type >5, click cell H2, type >30000, and press <Enter>.
This will filter clients that have taken more than five annual trips and have incomes greater than $30,000. Next, you
want to add a logical condition so that any clients who have taken more than seven annual trips are also selected,
regardless of their income.
5. Click any of the cells in the list range and select Data Advanced Filter from the menu.
The Advanced Filter dialog box appears, as shown in Figure 0-10. Since you opened the Advanced Filter with the
active cell in the list, the list range is already selected. You still have to specify what the criteria range is, however.
6. Click the Criteria range box and select the Criteria range—A1:H3.
You‘re ready to apply the advanced filter.
NOTE: Make sure you don‘t select the blank row between the criteria range and the list range, or the Advanced Filter
won‘t work!
7. Verify that the Filter the list, in-place option is selected and click OK.
The list range is filtered to match the criteria you specified in the criteria range. Notice the Status bar displays how
many records were found. You remove Advanced Filters just the same as AutoFilters.
Figure 0-11
Figure 0-12
When you filter a list, you may want to copy or extract the records that meet your search criteria. You must use an Advanced
Filter to copy filtered records to a new location. (Microsoft really should have let you copy filtered records with the much
simpler AutoFilter as well, but they didn‘t, so there‘s no use complaining about it.)
1. Clear the current criteria in the Criteria Range by selecting the cell range G2:H3 and pressing the
<Delete> key.
Since you will only need one row for your criteria you‘ll need to delete one of the rows in the criteria range.
2. Right-click the Row 2 heading and select Delete from the shortcut menu.
Next you need to enter a new set of search criteria. This time you want to find and then extract all the records that are in
the 55701 zip code.
23 | A D V A N C E E X C E L
4. Click any cell in the list range ( A4:H20) and select Data Advanced Filter from the menu.
The Advanced Filter dialog box appears, as shown in Figure 0-11. This time, instead of Filtering the list in place you
want to copy it to a new location in the worksheet.
5. Verify that the List Range and Criteria Range match what is shown in Figure 0-11, then select the
Copy to another location option in the Action section.
The last step in extracting the records from the 55701 zip code is to specify where you want to paste the filtered
records.
7. Click OK.
The Advanced Filter dialog box closes and Excel copies the records that meet the search criteria with the 55701 zip
code to the new location.
Quick Reference
To Copy or Extract Filtered Records:
1. Your worksheet should have at least three blank rows that can be used as a criteria
range above the list.
2. Copy the column labels from the list and paste them in the first blank row of the criteria
range.
3. In the rows below the criteria labels, type the criteria you want to match. Make sure
there is at least one blank row between the criteria values and the list.
4. Select Data Advanced Filter from the menu.
5. In the Advanced Filter dialog box, specify the list range and the criteria range.
6. Select the Copy to another location option.
7. Select the Copy to box, select the cell where you want to copy the filtered records and
click OK.
24 | A D V A N C E E X C E L
Lesson 2-6: Using Data Validation
Figure 0-13
The Settings tab of the
Data Validation dialog box
Figure 0-14
A drop-down list appears
when you select a
restricted cell.
Figure 0-15
Figure 0-16
Figure 0-15
You can help users enter accurate and appropriate information into your worksheets with Excel‘s Data Validation feature. Data
validation restricts the type of information that can be entered in a cell and can provide the user with instructions on entering
information in a cell.
1. Click cell I4 to select it, click the Bold button and the Center button on the Formatting toolbar,
type Purpose, and press <Enter>.
You have just entered a new field heading for your list. Notice that the border extends to include this column in your
list.
3. Select Data Validation from the menu and click the Settings tab if necessary.
The Data Validation dialog box appears, as shown in Figure 0-13. You want to provide the user with a list of entries
they can select from for the Purpose.
25 | A D V A N C E E X C E L
4. Click the Allow list arrow, select List, then click the Source box and type Business, Pleasure,
Other, Not Stated, as shown in Figure 0-13. Make sure the In-cell dropdown check box is
checked to display the list of valid entries whenever a cell in the Purpose column is selected.
You‘re ready to test your data validation rules.
6. Click the list arrow and select Pleasure from the list.
Excel enters the Pleasure option from the list. Move on to the next step to see what happens if you type an invalid entry.
9. Click the Column E column header to select the entire column, then select Data Validation
from the menu.
The Data Validation dialog box appears. You must specify that any entries in the selected cells must contain no more or
no less than two digits.
10. Click the Allow list arrow, select Text Length, click the Minimum text box and type 2, and then
click the Maximum text box and type 2.
You can also use the Data Validation dialog box to provide a user filling out your form with helpful information or
feedback.
12. Click the Input Message text box, type Enter the client’s state of residence and click
OK.
The dialog closes. Test out the data validation options for the state column.
26 | A D V A N C E E X C E L
Chapter One: Automating Tasks with Macros
If you find yourself performing the same task over and over again, you might want to consider creating a macro to complete
the task for you. A macro helps you perform routine tasks by automating them. Instead of manually performing a series of
time-consuming, repetitive actions, you can record a single macro that does the entire task all at once for you.
This entire chapter is devoted to macros. We start with the basics: learning how to record and play a macro. Next, you will
learn how to assign shortcut keys and toolbar buttons to your macros. Finally, you‘ll move into some advanced topics; how to
write and edit macros using the Visual Basic programming language.
27 | A D V A N C E E X C E L
Lesson 3-1: Recording a Macro
Figure 1-1
Enter a name for the macro
The Record Macro dialog
box
Specify where you want to
Figure 1-2 save the macro
Enter a description for the
The Macro Recorder macro
toolbar
Stop recording
A macro is a series of Excel commands and instructions that are grouped together and executed as a single command. Instead
of manually performing a series of time-consuming, repetitive actions in Excel yourself, you can create a macro to perform the
task for you. There are two ways to create a macro: by recording them or by writing them in Excel‘s built-in Visual Basic
programming language. This lesson explains the easy way to create a macro—by recording the task(s) you want the macro to
execute for you.
When you record a macro, imagine you‘re being videotaped; everything is recorded—all your commands, the data you enter,
even any mistakes you make! Before you record a macro, you should write down a script that contains all the steps you want
the macro to record. Practice or rehearse your script a couple times, to make sure it works, before you actually record it. If you
do make a mistake while recording a macro, don‘t worry—you can delete the existing macro and try again or you can edit the
macro‘s Visual Basic source code and fix the mistake (more on that later). Let‘s get started!
28 | A D V A N C E E X C E L
This Workbook: Stores the macro in the active or current workbook.
4. In the Macro name box, type DateStamp, then in the Description box, type This macro inserts
the current date.
Macro names can be no longer than 25 characters and cannot include spaces.
5. Click OK.
Stop button
The Record Macro dialog disappears and you return to the worksheet. Notice the Macro toolbar appears in the
document window, as shown in Figure 1-2. The Macro toolbar indicates that Excel is currently recording everything
you type and every command into the DateStamp macro. Do the next several steps very carefully—you don‘t want to
make a mistake and have it recorded in your macro!
6. Type =Today() and click the Enter button on the Formula bar.
The TODAY() function will display the current date in the active cell. That‘s OK for today, but not for any day after,
when the date changes. You need to copy the formula and then paste the resulting value using the Paste Special
command.
7. Make sure cell B3 is selected and click the Copy button on the Standard toolbar.
Next, use the Paste Special command to paste the resulting value of the TODAY() formula in the cell.
8. Make sure cell B3 is selected and select Edit Paste Special from the menu.
The Paste Special dialog box appears.
Quick Reference
9. Select the Values option under the Paste section and click OK.
To Record a Macro:
The Paste Special dialog box closes, and Excel pastes the value of the TODAY() formula in 1. Select Tools Macro
Record New Macro
cell B3. Next, format the cell. from the menu.
2. Enter a name and
10. Click the Bold button and then the Center button on the Formatting toolbar. description for the macro.
The active cell is now boldfaced and centered. This is the last step you want in the macro, 3. If you want, assign a
so you can stop the macro recorder. shortcut keystroke to your
macro and specify where
you want your macro to
11. Click the Stop button on the Macro Record toolbar. be saved.
The Macro toolbar closes indicating that you are no longer recording a macro. 4. Click OK and carefully
NOTE: If the Macro Record toolbar is no longer on your screen at this step, perform the actions you
want to include in your
just select Tools Macro Stop Recording from the menu. macro.
5. Click the Stop button on
the Macro Record toolbar
In the next lesson, you will learn how to play the macro you just recorded. when you‟re finished
recording your macro.
Or…
Select Tools Macro
Stop Recording from
the menu.
29 | A D V A N C E E X C E L
Lesson 3-2: Playing a Macro and Assigning a
Macro a Shortcut Key
Figure 1-3
The Macro dialog
box
Figure 1-4 In this lesson you get to play the DateStamp macro you recorded in the previous lesson. Once
Assigning a shortcut key to a you have created a macro you can assign a keystroke shortcut to it, such as <Ctrl> + <D>, to
macro in the Macro Options
dialog box make it faster and easier to access—something you‘ll learn in this lesson.
30 | A D V A N C E E X C E L
Lesson 3-3: Editing a Macro’s Visual
Basic Code Figure 1-5
The Microsoft Visual Basic
Editor
This lesson introduces you to the Visual Basic (also called VB or VBA) programming language. Visual Basic is the code Excel
uses to record macros. Okay, you‘re probably thinking, ―You can‘t be serious! I can‘t program my VCR!‖ Relax. This lesson is
meant to help you become familiar with the Visual Basic language and the Visual Basic editor so you can make minor changes
to your macros once you have recorded them. Just imagine you‘re learning several words in a foreign language so when
you‘re presented with a menu you‘ll recognize some of the entrées. Let‘s get started, and don‘t worry; it‘s not going to be
nearly as bad as you probably think it will be.
The best way to learn about Visual Basic is to view existing code. In this lesson we‘ll view and edit the DateStamp macro.
2. Select the DateStamp macro from the Macro name list and click Edit.
The Microsoft Visual Basic Editor program appears, as shown in Figure 1-5. Yikes! You‘re probably thinking, ―What is
all of that complex programming code doing on my screen?‖ Those funny-looking words aren‘t Hungarian, they‘re
Visual Basic—the code or language the macro you recorded is written in. Whenever you record a macro, Excel writes
and saves it in Visual Basic.
You don‘t have to learn Visual Basic to be proficient at Excel, but knowing the basics can be helpful if you ever want to
modify an existing macro. Take a closer look at the code for the DateStamp macro. Some of the procedures should
make a little sense to you. For example, the line ―Selection. Copy‖ is the copy procedure and the ―Selection. Paste‖ is
the paste procedure.
31 | A D V A N C E E X C E L
You decide that you no longer want the DateStamp macro to center and bold the current cell‘s contents. Before you
move on to the next step, look at the macro‘s code and see if you can guess which lines of code apply the bold and
center formatting.
4. Select the block of code beginning with Selection.Font.Bold = True and ending with End With, as
shown in Figure 1-5.
Delete the selected text.
6. Click the Save button on the Visual Basic Standard toolbar to save the code.
Now that you‘ve finished editing the macro‘s code, you can close the Visual Basic Editor.
7. Close the Visual Basic Editor by selecting File Close and Return to Microsoft Excel from the
menu.
The Visual Basic Editor window closes and you return to Excel. Try out your newly modified macro to see if it works.
8. Click cell A3, then select Tools Macro Macros from the menu.
The Macro dialog box appears.
Quick Reference
9. In the Macro name list, click the DateStamp macro, then click Run. To Edit a Macro’s Visual
The modified DateStamp macro runs, this time entering the current date without Basic Code:
formatting the cell. 1. Select Tools Macro
Macros from the
10. Save your work. menu.
2. Select the macro and
click Edit.
3. When you‟re finished
editing the macro‟s code
click the Save button and
then close the Visual
Basic Editor window.
32 | A D V A N C E E X C E L
Lesson 3-4: Inserting Code in an Existing
Macro
Figure 1-6
The Macro dialog box
Figure 1-7
Because of the risk of
viruses, you must enable
any macros in a workbook
Figure 1-6 Figure 1-7 when you open it.
Sub DateStamp() Sub ExpenseFillin() Figure 1-8
' '
' DateStamp Macro ' ExpenseFillin Macro
' ' Copying a portion of code
ActiveCell.FormulaR1C1 = "=TODAY()" Range("A5:C5").Select from the InsertDate macro
Range("C5").Activate
Selection.Copy
Selection.ClearContents
and pasting it in the
Selection.PasteSpecial
Paste:=xlValues, Range("A5").Select ExpenseFillin Macro
ActiveCell.FormulaR1C1 = "Jeff Nelson"
End Sub Range("B5").Select
ActiveCell.FormulaR1C1 = "45177"
Range("C5").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Selection.Copy
Selection.PasteSpecial
Paste:=xlValues,
End Sub
Let‘s face it—unless you‘re a programmer, it‘s unlikely that you will ever learn any of Visual Basic‘s hundreds of functions,
statements, and expressions, and that‘s okay. You have already learned how you can view and even edit Visual Basic code
created by Excel‘s macro recorder. A very useful technique you can use to edit and create macros is to insert code that has
been copied, or plagiarized, from another macro. This technique lets you add steps to your existing macros by recording the
steps you want to add in new macros, copying the appropriate code and inserting it in the existing macro.
1. Open the Lesson 3B workbook and save it as Employee Expenses (leave the current Macro
Practice workbook open).
If you do not know where your practice files are located, ask your instructor for assistance. When you open the Lesson
8B file a frightening-looking dialog box like the one shown in Figure 1-7 might appear. Macros are like miniature
programs, so there is an almost infinitesimally small chance that a macro in an Excel worksheet could in fact be a virus
created by some disgruntled, malicious loser. If you know where the workbook came from, it‘s probably safe to enable
the macros it contains.
2. If necessary, click Enable Macros.
Imagine this is an employee expense report you have to fill out once a week. Since you enter the same information in
this workbook on a regular basis, you have recorded a macro to perform some of the repetitive work of filling out the
form for you.
3. Select View Macro Macros from the menu.
The Macro dialog box opens. The name of the macro that fills in the basic, repetitive information is ExpenseFillin.
33 | A D V A N C E E X C E L
4. Select the macro ExpenseFillin and click Run.
The Macro dialog box closes, and Excel runs the ExpenseFillin macro, which fills in the employee name and number. It
would be nice if the ExpenseFillin macro also added the date you completed the Expense Report. You can do this by
copying the procedure from the DateStamp macro you created in the Macro Practice workbook and pasting it in the
code of the ExpenseFillin macro.
7. Select the block of code beginning with ActiveCell.FormulaR1C1 = "=TODAY()" and ending with
Selection.PasteSpecial Paste:=xlPasteValues, as shown in Figure 1-8, and click the Copy
button on the Visual Basic toolbar.
Now that you‘ve copied the procedure that inserts the current date, you must insert, or paste it into the appropriate place
in the ExpenseFillin macro.
9. Select View Macro Macros from the menu, select the macro ExpenseFillin and click Edit.
The Microsoft Visual Basic editor appears with code for the ExpenseFillin macro. You need to paste the copied
DateStamp code into the appropriate place in the ExpenseFillinMacro code.
10. Move the insertion point to the end of the line Range("C5").Select, press <Enter> to add a blank
line, then click the Paste button on the Visual Basic toolbar.
The copied code from the DateStamp macro is inserted into the ExpenseFillin macro. Compare your macro to the one
shown in Figure 1-8 (don‘t worry if your code is spaced differently and has different tabs).
11. Close the Visual Basic Editor by clicking the Close button.
It‘s time to test your macro.
12. Select Tools Macro Macros from the menu, select the ExpenseFillin macro and click Run.
Excel runs the ExpenseFillin macro, which now also adds the current date in cell C5. Clear the information the macro
entered and save the workbook to finish this lesson.
13. Select the cell range A5:C5, press the <Delete> key, and then save the workbook.
34 | A D V A N C E E X C E L
Lesson 3-5: Declaring Variables and Adding
Remarks to VBA Code
Figure 1-9
Using the Dim statement
to declare variables and
the remark statement („) to
add comments to Visual
Dim statement
Basic code.
Remark Figure 1-10
The syntax for the Dim
statement
Figure 1-9
You‘ve probably heard that programming is a lot like algebra. In algebra you use variables, like the r in the equation r2.
Programming uses variables too. You should always declare any variables when you use them in code. Declaring a variable is
like telling Excel ―I‘m going to be using a variable named ‗r‘ in my code.‖ In Visual Basic, you use the DIM statement to
declare variables, using the syntax DIM variablename As datatype, as shown in Figure 1-10. This lesson explains how to
declare variables using the Dim statement (you‘ll actually get to use the variables you declare in the next lesson.)
Another topic covered in this lesson is how to add remarks to your code. Code can be confusing—you can make it easier to
understand by adding explanatory remarks to it by adding REM statements. A REM statement doesn‘t do anything as far as the
code is concerned—it‘s just a way to add notes explaining the function of the code. You can add a REM statement by typing
an apostrophe before the comment. For example: ‗Adds the current date.
1. Make sure the Employee Expenses is the active workbook, then select View Macro View
Macros from the menu, select the macro ExpenseFillin and click Edit.
The Microsoft Visual Basic editor appears with the code for the ExpenseFillin macro. Since several other users
occasionally use this report, you decide you want to edit the macro so it prompts the user for their name and employee
number. You‘ll learn how to prompt the user for information or Input in the next lesson. For now, you have to declare
the variables for the employee name and number.
2. Add a blank line immediately above the line Range("A5").Select. Place the insertion point in the
blank line and type Dim EmployeeName As String and press <Enter>.
Remember, a variable is any piece of information that changes, like the x in an algebra problem. In the case of the
ExpenseFillin macro, the employee‘s name will be the variable. Variables must have a name, like the x in the algebra
problem. You name a variable a name declaring it with the Dim statement. The Dim statement must be entered in the
following syntax: Dim variablename as datatype. Here‘s what the arguments of the Dim statement mean:
35 | A D V A N C E E X C E L
VariableName: The name of the variable. Example: EmployeeName.
DataType: The type of data you want to use in the variable, such as a number, date, or text. See Table 1-1: Data
Types used in Variables for a list of data types. Make sure you add an As between the variable name and the data
type. Example: As String.
Since the line of code ―Dim EmployeeName As String‖ you just entered is a little confusing, you can add a REM
statement after it to explain what it does. Here‘s how:
3. Type 'Declares the EmployeeName variable as a text string and press <Enter>.
Next, you‘ll need to declare the Employee Number.
NOTE: Don‘t for get the ‗ apostrophe at the beginning of the remark! Otherwise VisualBasic will try to recognize the
text as a value.
36 | A D V A N C E E X C E L
Lesson 3-6: Prompting for User Input
Figure 1-11
An Input Box generated
from the InputBox
statement.
Figure 1-11
Figure 1-12
Sub ExpenseFillin() The edited ExpenseFillin
'
' ExpenseFillin Macro VBA code.
'
Dim EmployeeName As String
'Declares the EmployeeName variable as a text string
Dim EmployeeNo As Long
'Declares the EmployeeNo variable as an integer
EmployeeName = InputBox("Enter the Employee's Name.") The InputBox function
EmployeeNo = InputBox("Enter the Employee Number.")
Range("A5:C5").Select
Range("C5").Activate
Selection.ClearContents
Range("A5").Select
ActiveCell.FormulaR1C1 = EmployeeName
Range("B5").Select
ActiveCell.FormulaR1C1 = EmployeeNo
Worksheets("Sheet1").PageSetup.CenterFooter = "Expense Report for: " &
EmployeeName
Range("C5").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= False,
Transpose:=False
End Sub
Figure 1-12
When creating macros and code it is often useful to prompt the user for information. You can then use this information in any
number of ways—place it in a cell, use it in a calculation, or print it in a header or footer.
This lesson explains one of the easiest methods of prompting the user for information—using the InputBox function. The
InputBox function prompts the user for information by displaying a dialog box like the one shown in
Figure 1-11. The syntax for the InputBox function is InputBox(Prompt) where Prompt is the message you
want to display (usually enclosed in quotation marks ― ‖).
Quick Info
1. Make sure the Visual Basic editor is still open and displays the ExpenseFillin code.
2. Place the insertion point immediately after the 'Declares the EmployeeNo variable as an integer
statement, press <Enter>, type EmployeeName = InputBox("Enter the Employee's Name."),
and press <Enter>.
As you type, Visual Basic displays a small window that displays information about the function you‘re entering and its
parameters. This statement will display an InputBox, as shown in Figure 1-11, which will ask the user to enter the
EmployeName variable.
37 | A D V A N C E E X C E L
4. Find the ActiveCell.FormulaR1C1 = "Jeff Nelson" statement and edit it so it reads
ActiveCell.FormulaR1C1 = EmployeeName.
Make sure you remove the quotation marks! Now the macro will insert the EmployeeName variable the
You can combine, or user enters in the Input Box instead of the name ―Jeff Nelson.‖
concatenate, two
pieces of 5. Find the ActiveCell.FormulaR1C1 = "45177" statement and edit it so it reads
information using ActiveCell.FormulaR1C1 = EmployeeNo and press <Enter>.
the ampersand (&) You decide to enter the text from the EmployeeName variable in the page footer for the worksheet as
symbol. For example, well.
you can create the
message “Expense 6. Type Worksheets("Sheet1").PageSetup.CenterFooter = "Expense Report
Report for: Bill for: " & EmployeeName.
Smith” by combining
a text string
"Expense Report
for" with a variable,
such as
EmployeeName.
That last statement was a bit confusing—here‘s what it does. We‘ll start from the end of the code and work our way to
the beginning. Employee Name is the variable you declared and it equals whatever the user enters in the InputBox.
Before that is the ampersand symbol (&), which combines the EmployeeName variable with the text message
―Expense Report for: ‖. Note that the text message (or text string) must be enclosed in quotation marks (―‖). The first
part of the statement, Worksheets(“Sheet1”).PageSetup.CenterFooter, refers to the center footer of the Sheet1
worksheet. So the line of code tells Excel you want the center footer of Sheet1 to equal, or display the message
―Expense Report for: EmployeeName variable‖ or whatever name the user enters in the InputBox.
You‘re ready to test your macro.
7. Click the Save button on the Visual Basic toolbar to save the macro, then close the Visual Basic
Editor by clicking the Close button or selecting File Close from the menu.
The Visual Basic editor closes and you return to the Excel program screen.
Quick Reference
To Use the Inputbox
8. Select View Macro Macros from the menu, select ExpenseFillin and click Run.
Statement:
Add an Input statement
An Input Box appears asking you to input the employee‘s name, as shown in Figure 1-11.
using the syntax
InputBox(Promp).
9. Type in your name, click OK, type 7000 in the second Input Box, and click OK.
The ExpenseFillin macro fills in the Expense report with the EmployeeName and
EmployeeNo variables you entered in the two Input Boxes. Preview the workbook to
verify that the EmployeeName also appears in the workbook footer.
12. Select the cell range A5:C5 and press the <Delete> key, then save your work.
38 | A D V A N C E E X C E L
Chapter Six: Data Analysis and PivotTables
Once you have created a list, there are many ways to analyze its data. You should already know some basic ways to analyze
information, such as filtering records. This chapter explains more advanced and powerful methods of analyzing list
information.
Creating a PivotTable feature is usually the best way to summarize and analyze list data—which is why we‘ll spend more than
half of the chapter discussing it. A PivotTable is a way to summarize list information. Peek at Figure 1-1 and Figure 1-2 on the
next page to see how much easier it is to make sense of numbers in a list with a PivotTable. This chapter explains the ins and
outs of PivotTables—how to create them, modify their structure, and edit the data a PivotTable is based on.
This chapter also includes lessons on several other ways to summarize and analyze worksheet information, such as how use
Excel‘s subtotal function, how to create database-specific formulas, and how to outline your worksheets.
39 | A D V A N C E E X C E L
Lesson 6-1: Creating a PivotTable
Figure 1-1
It‟s difficult to see
the bottom line in a
long list like this.
Figure 1-2
This Pivot Table
displays a summary
view of Figure 1-1‟s Figure 1-2
information.
Figure 1-3 Specify where you want to put your
Figure 1-1 PivotTable: In a new worksheet or
Step 1 of 3 of the embedded in an existing worksheet
PivotTable Wizard
asks where the data
you want to analyze
comes from and if
you want to create a
PivotTable or a
PivotChart with a
PivotTable.
Figure 1-4 Sets advanced formatting, layout,
Figure 1-4 memory management, and
external data options for your
Step 3 of 3 of the PivotTable report
PivotTable Wizard Figure 1-3
asks where you
want to put the
PivotTable.
Figure 1-5
This newly created
PivotTable (without
any information yet).
Figure 1-5
Creating a PivotTable is remarkably easy. You create PivotTables using the PivotTable Wizard, which asks which fields you
want to include in the PivotTable, how you want your PivotTable organized, and which types of calculations your PivotTable
should perform. PivotTables may sound confusing, but they will make a lot more sense when you‘ve actually created one.
40 | A D V A N C E E X C E L
2. Make sure the cell pointer is located in the list (A1:I200) and select Insert PivotTable and
PivotChart Report from the menu.
The First Step of the PivotTable Wizard dialog box appears. Here you must specify the location of the data you want to
use in your PivotTable. There are four options:
Microsoft Office Excel list or database: Creates a PivotTable from data in columns on your worksheet (the
most commonly used option).
External data source: Creates a PivotTable from data stored in a file or database outside of the current
workbook or Microsoft Excel.
Multiple consolidation ranges: Creates one PivotTable from multiple cell ranges in different worksheets.
Another PivotTable: Creates a PivotTable from another PivotTable in the same workbook.
You also have to specify if you want to create a PivotTable Report or a PivotTable Report along with a corresponding
PivotChart report.
3. Verify that the Microsoft Office Excel list or database and the PivotTable options are both
selected and click Next.
Step Two of the PivotTable Wizard appears. You need to tell the PivotTable Wizard where the data you want to use in
the PivotTable is located. Because the cell pointer was located inside the list when you started the PivotTable Wizard,
the cell range of the list (A1:I200) is already selected.
4. Click Next.
The third and last step of the PivotTable Wizard appears, as shown in Figure 1-4. Here‘s where you tell Excel to put
your PivotTable report. You can place your PivotTable report in:
A new worksheet
An existing worksheet. Quick Reference
To Create a PivotTable:
5. Verify that the New worksheet option is selected and click Finish. 1. Make sure the cell pointer
The PivotTable Wizard dialog box closes and the PivotTable appears on a new is located in the list.
worksheet, as shown in Figure 1-5. Notice that the PivotTable is empty—that‘s 2. Select insert Pivot
because we haven‘t specified the data we want to analyze yet—something you‘ll Table and PivotChart
learn in the next lesson. Report from the menu.
3. Select the location of the
data you want to include
in your PivotTable report
and the type of report
(PivotTable report or
PivotTable with PivotChart
report) and click Next.
4. In Step 2 make sure the
list range is selected and
click Next.
5. In Step 3, specify a
location for the PivotTable
(a new worksheet or an
existing worksheet.)
6. Click Finish.
41 | A D V A N C E E X C E L
Lesson 6-2: Specifying the Data a PivotTable
Analyzes
Row area Data area Column area
Figure 1-6
Dragging the Office field PivotTable Field List
Drag the field you want
from the PivotTable to summarize the row,
toolbar to the Column area column, or data area of
of the PivotTable. the PivotTable
Figure 1-7
The PivotTable
summarizing the total
tickets sold by Destination … or select the field
and Office. area and the field, and
click the Add To button.
Figure 1-6
Destination field
Figure 1-7
1. Drag the Destination field from the PivotTable Field List to the ROW area of the PivotTable diagram.
The Destination field appears at the top of the ROW area in the PivotTable. Next, make the Office field the column
heading for the PivotTable.
2. Drag the Office field from the PivotTable Field List to the COLUMN area of the PivotTable diagram,
as shown in Figure 1-6.
You have selected the Destination field to be the row heading and the Office field to be the column heading for your
PivotTable. Now you need to select the field you want to summarize.
3. Drag the Tickets field from the PivotTable Field List to the DATA area of the PivotTable diagram.
Compare your dialog box with the one shown in Figure 1-7.
The neat thing about PivotTables is that their information is dynamic. What this means is once you‘ve created a
PivotTable, you can rearrange or ―pivot‖ it to view its data in different ways. For example, you could rearrange the
PivotTable you just created so that it summarizes the amount of the total ticket sales instead of the total number of
tickets sold.
42 | A D V A N C E E X C E L
4. Drag the Sum of Tickets field button (located in cell A3) off the PivotTable Sum of Tickets
diagram. field button
The PivotTable will no longer total the number of tickets sold. You can easily summarize another field by dragging it
onto the DATA area of the PivotTable diagram.
5. Drag the Total field to the DATA area of the PivotTable diagram.
You can also rearrange a PivotTable‘s headings.
6. Drag the Destination field from the ROW area of the PivotTable diagram to the COLUMN area.
7. Drag the Office field from the COLUMN area of the PivotTable diagram to the ROW area.
Hopefully, you‘re starting to understand the true power of PivotTables. PivotTables can usually make information
stored in even the longest lists easy to understand. And once you make a PivotTable you can change the information it
summarized in an instant, simply by dropping and dragging.
Quick Reference
To Specify PivotTable
Data:
1. Make sure the cell pointer
is located in the list.
2. Drag the field names you
want to summarize to the
appropriate section of the
PivotTable diagram
(Page, Column, Row, or
Data).
43 | A D V A N C E E X C E L
Lesson 6-3: Changing a PivotTable's
Calculation
Figure 1-8
The PivotTable Field
dialog box.
Figure 1-9
The PivotTable toolbar. Figure
In the previous lesson, you learned how to change the data 1-9 to include in the PivotTable report.
you wanted
Field Settings
Figure 1-10
You can also change how a PivotTable summarizes its information. For example, you might want a
button PivotTable to display averages instead of totals.
The PivotTable Figure 1-8
summarized by the Sum 1. Click cell B5 and select Window Freeze Panes from the menu.
of total sales. Now the column and row headings to the left and above the active cell (B5) will always be visible as you
Figure 1-11 scroll through the worksheet.
The PivotTable
summarized by the 2. Scroll down to row 23.
Average of total sales. The PivotTable has created column totals, which calculates the total number of reservations made at each
office.
Quick Reference
5. Select Average from the Summarize by list and click OK.
To Change the Calculation
The PivotTable Field dialog box closes and the PivotTable displays the average total sales.
Used in a PivotTable:
1. Make sure the cell pointer
is located in the
PivotTable and click the
Field Settings button on
the PivotTable toolbar.
2. Select the calculation you
want to use from the
Summarize by list and
click OK.
44 | A D V A N C E E X C E L
Lesson 6-4: Selecting What Appears in a
PivotTable
Figure 1-12
Using a page field to filter
summary information in a
PivotTable.
Figure 1-13
Dragging a field to the
Page Field area of a
PivotTable report.
Figure 1-14
You can filter which information is summarized in a PivotTable by clicking a row or column field‘s drop-down arrows and
selecting the items you want to include in the PivotTable report or by adding a page field to the PivotTable. In this lesson,
you‘ll learn how to filter the information that is included in a PivotTable Report using both methods.
1. If necessary, find and open the Lesson 6B workbook and save it as PivotTable.
If you do not know where your practice files are located, ask you instructor for help.
2. Make sure sheet 1 is the active sheet and click the Office field list arrow located in cell A4.
A list appears beneath the Office field, as shown in Figure 1-12. Check the values that you want in your PivotTable and
uncheck those you don‘t.
field
3. Remove the check mark from the Blaine, Bloomington, Brainerd, Brooklyn Center, and Duluth
boxes and click OK.
You can also filter the information that appears in a PivotTable report by adding a Page Field to the PivotTable.
4. Drag the Commission field to the PAGE area of the PivotTable diagram.
Now you will be able to filter the PivotTable using the commission field and display data for sales with commissions,
sales without commissions, or both.
5. Click the Commission field list arrow, select Yes and click OK.
The PivotTable displays only information for commissioned sales.
45 | A D V A N C E E X C E L
Lesson 6-5: Grouping Dates in a PivotTable
Figure 1-15
Summarizing ticket
sales by date.
Figure 1-16
The Grouping dialog
box. Figure 1-15
Figure 1-17
Grouping the dates in
the PivotTable by
months.
Figure 1-16
Select a date
increment to
group by
Figure 1-17
PivotTables can usually summarize information without any outside help from you. When you want to summarize a list by
dates, however, you will probably need to coach Excel and tell it how you want to group the information in the PivotTable: by
days, months, quarters, or years. In this lesson, we‘ll rearrange out PivotTable and summarize its information by month. First,
you need to rearrange your PivotTable to summarize it by date.
1. Drag the Office field off the PivotTable diagram. Drag the Destination field from the
Column area of the PivotTable to the Row area.
Quick Reference
Next, you need to add the Date field to the PivotTable‘s Column area.
To Group Information by
Date or Time:
2. Drag the Date field to the Column area of the PivotTable.
1. Select the row or column
Now the PivotTable summarizes ticket sales by destination and date as shown in Figure 1-15. The only
heading that contains the
problem is that the PivotTable summarizes the dates by day—making the summary information rather
date or time value you
meaningless. You can make the PivotTable more useful by grouping the days into months using the
want to group by and
Group command. First you need to specify what information you want to group by—the dates.
click the Group button
on the PivotTable
toolbar. 3. Click the Date field located in cell B3 then select Data Group and Outline
Or… Group from the menu.
Select any row or
column heading that The Grouping dialog box appears, as shown in Figure 1-16. You need to select a date or time interval by
contains the date or time which to group.
value you want to group
by and select Data
Group and Outline 4. Select Months from the By list and click OK.
Group from the menu. The Group dialog box closes and the PivotTable groups the dates by month, as shown in Figure 1-17.
2. Specify the starting and
ending dates and the
interval you want to
group the dates or time
by, then click OK.
46 | A D V A N C E E X C E L
Lesson 6-6: Updating a PivotTable
After making changes
to the list, the Figure 1-18
PivotTable still displays
the old values
A PivotTable that needs
to be refreshed.
Figure 1-19
The Refreshed
Figure 1-18
PivotTable.
Figure 1-19
Refresh Data
button
If you modify the source data a PivotTable is based on, the PivotTable isn‘t automatically updated. Instead you Other Ways to Refresh a
must manually refresh the PivotTable anytime you change its underlying source data. This lesson explains how PivotTable:
to do just that.
Select Data Refresh
Data from the menu.
1. Click cell A3 and then click the Field Settings button on the PivotTable toolbar. Select Sum from
the dialog box, and click OK.
Now the PivotTable will display the Sum of the total, instead of the Average.
2. Click the Promotion Sales tab. Click cell G19, type 100 and press <Enter>.
Obviously, Philip Grahams didn‘t sell 100 tickets to Boston, but this is a big enough number that you will be able see
the changes in the PivotTable‘s February column when you update it.
3. Click the Sheet1 worksheet tab to return to the PivotTable.
Quick Reference
Look at cell C5, the February column. The PivotTable does not reflect the increased ticket sales you
To Refresh a PivotTable:
made to the list, as shown in Figure 1-18.
4. Click anywhere in the PivotTable and click the Refresh Data button on the Click the Refresh Data
button on the PivotTable
PivotTable toolbar. toolbar.
The PivotTable is refreshed and correctly displays the current list data, as shown in Figure 1-19. Or…
5. Go back and change cell G19 back to 1, and press <Enter>. Click the Sheet1 Select Data Refresh
worksheet tab to return to the PivotTable and click the Refresh Data button on the Data from the menu.
PivotTable toolbar.
That‘s it—we‘re finished working with PivotTables! PivotTables are the most powerful way to summarize
information in a list, but they‘re not the only method you can use. The remainder of this chapter explores
some of the other ways to summarize list information.
47 | A D V A N C E E X C E L
Lesson 6-7: Formatting and Charting a
PivotTable
Figure 1-20
AutoFormatting a
PivotTable Report.
Figure 1-21
The completed PivotChart.
Scroll up or down to see all the
PivotTable report formats
Figure 1-20
Figure 1-21
This lesson explains how you can quickly format a PivotTable report using the AutoFormat command and how to create a
PivotChart—both new features introduced in Excel 2003.
First, let‘s discuss how to format your PivotTable with AutoFormat. AutoFormat is a built-in collection of formats such as font
sizes, patterns, and alignments you can quickly apply to a PivotTable report. AutoFormat lets you select from 20 different
preset formats. AutoFormat is a great feature if you want your PivotTables to look sharp and professional, but don‘t have the
time to format them yourself.
1. Make sure the cell pointer is located in the PivotTable report and click the
Format Report button on the PivotTable toolbar. Format Report
button
The AutoFormat dialog box appears, as shown in Figure 1-20. You can format your PivotTable report using a preset
format.
48 | A D V A N C E E X C E L
2. Scroll down the AutoFormat dialog box, select the Table 2 format and click OK.
Chart Wizard
The PivotTable is formatted with the preset Table 2 formatting settings. button
Let‘s move on to this lesson‘s other topic; creating a PivotChart. A PivotChart is similar to an Other Ways to Insert a
ordinary chart created in Excel, except that it plots a PivotTable‘s information. PivotCharts differ Chart:
from ordinary Excel charts because they are dynamic, just like PivotTable reports. You can change
Select Insert Chart
a PivotChart‘s structure just like you would with a PivotTable.
from the menu.
3. Make sure the cell pointer is located in the PivotTable report and click the Chart Wizard button on
the PivotTable toolbar.
Excel creates a chart from the PivotTable and places it on a new sheet tab, labeled Chart1.
You can format and work with a PivotChart just like you would with a regular chart. Since there‘s so
much information in our PivotTable, the PivotChart we just created looks cluttered. As with Clustered Column
PivotTables, you can specify which items you want to appear in a PivotChart. Chart Type
4. Click the Destination drop-down list located below the chart and remove the checkmarks from all
the destinations except Boston, Cancun, Chicago, and Dallas, and click OK.
Only the specified destinations are plotted on the PivotChart. Let‘s change the chart type to make
our PivotChart easier to understand.
6. Select a Clustered Column Chart from the Chart Sub-Type list and click OK.
The chart type is changed to a clustered column chart, as shown in Figure 1-21.
Just about everything you can do to a PivotTable report you can do to a PivotChart. For example,
you can easily add, change, remove, or rearrange what the PivotChart plots.
Quick Reference
7. Drag the Sum of Total field (located in the upper left corner of the chart) from the To Format a PivotTable:
PivotChart back to the PivotTable Field List to remove it. Make sure the cell pointer
is located in the
Since the PivotChart has no data to plot, it displays the message ―Drop Data Items Here.‖
PivotTable report and
click the Format Report
8. Drag the Tickets field from the PivotTable toolbar to the empty Data area of the button on the PivotTable
PivotChart. toolbar. Select the
formatting you want to
The PivotChart now plots the total number of tickets sold to each destination. apply and click OK.
To Create a PivotChart:
9. Save your work and then close the Pivot Table worksheet.
Place the cell pointer
That‘s it—we‘re finished working with PivotTables and PivotCharts! PivotTables are the most powerful way anywhere in a PivotTable
to summarize information in a list, but they‘re not the only method you can use. The remainder of this report and click the Chart
Wizard button on the
chapter explores some of the other ways to summarize list information. PivotTable toolbar. You
will probably have to
change the chart type.
Or…
Create a PivotTable and
PivotChart from scratch.
See the instructions for
creating a PivotTable.
To Modify a PivotChart:
Modify a PivotChart the
same as you would a
49 | A D V A N C E E X C E L PivotTable—drag and
drop fields to and from the
PivotTable toolbar and the
PivotChart.
Lesson 6-8: Creating Subtotals
Field to group by Figure 1-22
The Subtotal dialog box.
Summarize groups using
this function Figure 1-23
Column levels
buttons
Figure 1-23
So far in this chapter, we‘ve been summarizing information in a list using PivotTables. Another quick and easy way to group
and summarize data is to use Excel‘s subtotals feature. Usually you create subtotals with the SUM function, but you can also
create subtotals using functions such as COUNT, AVERAGE, MAX, and MIN.
1.
Show details button
Open the workbook named Lesson 6C.
If you do not know where your practice files are located, ask your instructor for help.
You need to sort the list before you use the Subtotals command. You want to sort the list alphabetically by destination.
2. Click any cell in the E column and click the Sort Ascending button on the Standard toolbar.
The list is sorted alphabetically by destination. Now that the list is sorted, you can use the Subtotals command.
3. Make sure the active cell is located within the list and select Data
Figure
Subtotals from 1-24
the menu.
Sort Ascending
The Subtotal dialog box appears, as shown in Figure 1-22. You want to summarize the list button
based on the Destination field—the field you sorted in the previous step.
4. Select Destination from the At each change in list, then select Sum from the Use function list.
This will create subtotals every time the destination changes (which is why you had to sort the list based on
Column Level destination back in Step 2). Next, you need to specify that you want to add subtotals to the Annual Trips and
buttons Annual Cost of Tickets fields.
5. In the Add subtotal to list, check the Tickets check box, and the Total check box (you may have to
scroll up or down to find them). Make sure the other check boxes in the list aren’t checked.
This will add subtotals to the Tickets and Total columns.
6. Make sure the Replace current subtotals and Summary below data check boxes are checked.
Compare your Subtotal dialog box to the one in Figure 1-22.
50 | A D V A N C E E X C E L
7. Click OK.
The dialog box closes and Excel summarizes the list and calculates the subtotals for each time the destination field
changes. Notice Excel displays the outline symbols to the left of the worksheet, as shown in Figure 1-23. We‘ll save
outlining for another lesson. For now, try using the Outline buttons to hide the list details.
10. Make sure the active cell is located within the list and select Data Subtotals from the menu, then
click Remove All.
The subtotals and outlining are removed from the list. You can remove Subtotals from a workbook at any time.
Quick Reference
To Calculate Subtotals:
1. Make sure the list is
sorted.
2. Select Data Subtotals
from the menu.
3. Enter the appropriate
information in the Subtotal
dialog box and click OK.
To Remove Subtotals:
Make sure the active cell
is located within the list,
then select Data
Subtotals from the menu
and click Remove All.
51 | A D V A N C E E X C E L
Lesson 6-9: Using Database Functions
Figure 1-25
Using the Insert Function
tool to create a DSUM
formula.
Figure 1-26
The syntax of the DSUM
function.
Figure 1-27
The DSUM function totals Figure 1-25
only those records that =DSUM(A1:I23, "Annual Trips", C25:C26)
meet your criteria.
Function Database Field Criteria
the range of the name or number of the range of cells
cells that make the column that is used that contains the
up the list in the function conditions you want
Figure 1-26 to specify
Field used in
DSUM formula
Criteria range
DSUM formula
Figure 1-27
Excel‘s database functions perform calculations only for records that meet the criteria you specify. For example, you might
only want to count tickets that were sold to Boston. All the database functions use the same basic syntax =Function(database,
field, criteria). These arguments (parts) of database functions include:
Database: Is the cell range that makes up the list or database.
Field: Indicates which column is used in the function. You can refer to fields by their column labels as long as you
enclose them with double quotation marks, such as "Name". You can also refer to fields as a number that represents the
position of the column in the list: 1 for the first column in the list, 2 for the second, and so on. Make sure you refer to their
position in the list, and not the column heading numbers!
Criteria: Is a reference to the cell or cell range that specifies the criteria for the function.
This lesson explains how to use database functions by creating a formula with the simplest database function—the DSUM
function.
52 | A D V A N C E E X C E L
2. Click cell C25 (scroll down if necessary), click the Bold button on the Formatting toolbar, type
Purpose and press <Enter>.
Next, enter the criteria the DSUM function will use (you‘ll see how the criteria works later when we actually create a
DSUM formula.
4. Make sure the active cell is C27, then click the Insert Function button on the Formula bar.
The Insert Function dialog box appears.
Insert Function
button
5. Select Database from the Or select a category list, select DSUM from the Select a Function list, and
click OK.
The Function Arguments dialog box appears, as shown in Figure 1-25. You‘re ready to start entering the
DSUM formula to calculate the total for Annual Trips amounts for only those records that have
―Business‖ in the Purpose column. The first argument in the DSUM function is to define the database— Collapse Dialog
the cell range that makes up the list. button
6. Click the Database text box and select the entire list—the cell range A1:I23 (you may have to use
the Collapse dialog box button).
The second argument in the DSUM function is to define the Field—the column that is used in the function. You can
enter the Field by typing the column label enclosed between double quotation marks, such as "Annual Trips" or as a
number that represents the position of the column in the list: 1 for the first column, 2 for the second column, etc. For
example, the column you want to total, Annual Trips, is the seventh column in the list, so you would type either 7 or
"Annual Trips" for the Field argument.
8. Click the Criteria text box and select the cell range C25:C26.
The cell range C25:C26 contains both the column label, Purpose, and the criteria, Business.
53 | A D V A N C E E X C E L
11. Save your work.
LOOKUP FUNCTIONS
As already mentioned, Excel can produce varying results in a cell, depending on conditions set by you. For
example, if numbers are above or below certain limits, different calculations will be performed and text
messages displayed. The usual method for constructing this sort of analysis is using the IF function.
However, as already demonstrated, this can become large and unwieldy when you want multiple conditions
and many possible outcomes. To begin with, Excel can only nest seven IF clauses in a main IF statement,
whereas you may want more than eight logical tests or "scenarios.‖ To achieve this, Excel provides some
LOOKUP functions. These functions allow you to create formulae which examine large amounts of data and
find information which matches or approximates to certain conditions. They are simpler to construct than
nested IF‘s and can produce many more varied results.
Lookup
Before you actually start to use the various LOOKUP functions, it is worth learning the terms that you will
come across, what they mean and the syntax of the function arguments.
Vector Lookup
A vector is a series of data that only occupies one row or column. LOOKUP will look through this row or
column to find a specific value. When the value is found, a corresponding "result" in the adjacent row or
column is returned. For example, column D of a spreadsheet may contain figures, and the adjacent column E
contains corresponding text. LOOKUP will search for the requested figure in column D and return the
corresponding text from column E.
Quick Reference
The syntax for LOOKUP is as To Use the DSUM
follows; Function in a Formula:
=LOOKUP( lookup_value , lookup_vector , result_vector ) Write the formula using
the syntax
The lookup_value represents the number or text entry to look for; the lookup_vector is the=DSUM(database,
area in which tofield,
search for the lookup_value; the result_vector is the adjacent row or column where the criteria).
corresponding
value or text is to be found. Or…
1. Click
It is essential that data in the lookup vector is placed in ascending order, i.e. numbers from the Insert Function
lowest
button on the Standard
to highest, text from A to Z. If this is not done, the LOOKUP function may return the wrong result.
toolbar to open the
Function arguments
dialog box.
2. Select Database in the
Function category list,
select DSUM in the
Function name list, and
click OK.
3. Enter the required
arguments for the DSUM
function.
54 | A D V A N C E E X C E L
In the diagram, column D contains varying salaries, against which there is a company car in column E which
corresponds to each salary. For example, a £20030 salary gets a Golf, a £35000 salary gets a Scorpio. A
LOOKUP formula can be used to return whatever car is appropriate to a salary figure that is entered. In this
case, the lookup_value is the cell where the salary is entered (B13), the lookup_vector is the salary column
(D3:D11), and the result_vector is the car column (E3:E11). Hence the formula;
=LOOKUP(B13,D3:D11,E3:E11)
Typing 40000 in cell B13 will set the lookup_value. LOOKUP will search through the lookup_vector to
find the matching salary, and return the appropriate car from the result_vector, which in this case is Mercedes.
Alternatively, the formula could be simplified and cell references avoided by using Formula, Define Name to
give appropriate range names. Call B13 Salary, D3:D11 Salaries and E3:E11 Cars. The LOOKUP formula
could then be simplified to;
=LOOKUP(Salary,Salaries,Cars)
One of the advantages of the LOOKUP function is that if the exact lookup_value is not found, it will
approximate to the nearest figure below the requested value. For instance, if a user enters a Salary of
23000, there is no figure in the Salaries range which matches this. However, the nearest salary below 23000 is
20030, so the corresponding car is returned, which is a Golf. This technique is very useful when the
lookup_vector indicates grades or "bands.‖ In this case, anyone in the salary "band" between 20030 and
25000 gets a Golf. Only when their salary meets or exceeds 25000 do they get a Sierra.
55 | A D V A N C E E X C E L
¾ To insert a lookup function:
Mouse
i. Click the drop down arrow next to the LOOKUP AND REFENCE button in the
FUNCTION LIBARY
group on the FORMULAS Ribbon;
ii. A dialog box appears displaying the two versions of LOOKUP. There are two syntax forms; the
first is the
"array" and the second the "vector.‖
The second of these forms, the "vector" LOOKUP is by far the most useful, and it is
recommended that you only use this form.
Hlookup
The horizontal LOOKUP function (HLOOKUP) can be used not just on a "vector" (single column
or row of data), but on an "array" (multiple rows and columns). HLOOKUP searches for a
specified value horizontally along the top row of an array. When the value is found, HLOOKUP
searches down to a specified row and enters the value of the cell. This is useful when data is
arranged in a large tabular format, and it would be difficult for you to read across columns and
then down to the appropriate cell. HLOOKUP will do this automatically.
The syntax for
HLOOKUP is;
56 | A D V A N C E E X C E L
Whatever the amount a customer wants to borrow, he may pay up to five different rates of interest
depending on whether the loan is over 10, 15 or more years. The HLOOKUP function will find a
specific amount, then move down the array to find the appropriate interest rate for the required time
period.
Designate cell A51 as the cell to hold the amount, i.e. the lookup_value; cells C43:H48 are the
table_array; the row_index_number will be 2 if a customer wants the loan over 10 years, 3 if he
wants the loan over 15 years, and so on. Cell B51 holds this formula;
=HLOOKUP(A51,C43:H48,3)
The above formula looks along the top row of the array for the value in cell A51 (30000). It
then moves down to row 3 and returns the value 15.00%, which is the correct interest rate for a
£30000 loan over 15 years. (Range names could be used here to simplify the formula).
As with the LOOKUP function, the advantage of HLOOOKUP is that it does not necessarily have
to find the exact lookup_value. If, for example, you wanted to find out what interest rate is
applicable to a £28000 loan, the figure 28000 can be entered in the lookup_value cell (A51)
and the rate 14.30% appears. As before, Excel has looked for the value in the array closest to, but
lower than, the lookup_value.
Vlookup
The VLOOKUP function works on the same principle as HLOOKUP, but instead of searching
horizontally, VLOOKUP searches vertically. VLOOKUP searches for a specified value vertically
down the first column of an array. When the value is found, VLOOKUP searches across to a
specified column and enters the value of the cell. The syntax for the VLOOKUP function follows
the same pattern as HLOOKUP, except that instead of specifying a row index number, you would
specify a column index number to instruct VLOOKUP to move across to a specific column in the
array where the required value is to be found.
57 | A D V A N C E E X C E L
period is entered in cell A54 and in B54 the VLOOKUP formula is contained;
58 | A D V A N C E E X C E L
=VLOOKUP(A54,C43:H48,5)
The cell A54 is the lookup_value (time period), the table_array is as before, and for this
example rates are looked up for a loan of £40000, hence the column_index_number 5. By
changing the value of cell A54, the appropriate rate for that time period is returned. Where the
specific lookup_value is not found, VLOOKUP works in the same way as HLOOKUP. In
other words, the nearest value in the array that is less than the lookup_value will be returned.
So, a £40000 loan over 17 years would return.
Lesson 6-10: Grouping and
Outlining a Worksheet
Figure 1-28 Column Level
buttons
A worksheet displayed in
Outline view. Row Level
buttons
Figure 1-29
Displaying and hiding an
outline‟s detailed records Hide Detail
by clicking the group Hide button
or Show Details button.
Figure 1-28
Many spreadsheets are created in a hierarchical style. For example, a worksheet might contain
a column for each month, followed by a total column. By outlining your worksheets, you
make them easier to understand and read. Instead of sifting through irrelevant information,
you can collapse an outline to display each group‘s total or bottom line.
There are several ways to outline a workbook:
Using the Subtotals Feature: The Data Subtotals command calculates
subtotal and grand total values for the labeled columns you select. Excel automatically
inserts and labels the total rows and outlines the list. We covered creating and working
Hide Details with subtotals earlier in this chapter.
button
Using the Consolidate Feature: You can consolidate several sheets by selecting
Data Consolidate from the menu.
Using the Auto Outline Feature: The Data Group and Outline Auto Outline
command automatically outlines a selected range of cells or the entire worksheet, based
on formulas and the direction of references.
Manually Creating an Outline: You can group rows and columns manually by
Show Details selecting them and selecting Data Group and Outline Group from the menu.
button
This lesson explains how to use the third and fourth methods and how to work with an
outline.
1. Open the Lesson 6E workbook.
If you don‘t know where your practice files are located, ask your instructor for
assistance. Row Level 2
We‘ll start this lesson by manually grouping the rows for the Blaine office. button
2. Select rows 5 and 6 and select Data Group and Outline Group
from the menu.
Excel groups the selected rows in an outline. Notice the Hide Details button that
appears to the left of the worksheet. Clicking a Hide Details button hides, or collapses,
its group of records.
3. Click the Hide Details button to the left of the worksheet.
Excel hides the details, rows 5 and 6, for the Blaine office and changes the Hide Column Level 2
Details button ( ) to a Show Details button ( ), indicating it contains hidden records. button
Clicking the Show Details button displays, or expands, its group of records.
4. Click the Show Details button to the left of the worksheet.
Excel displays the hidden records. It‘s just as easy to ungroup records as it is to group
Quick Reference
them. To Manually Group
5. Select rows 5 and 6 and select Data Group and Outline Ungroup Columns or Rows:
from the menu. Select the columns or
Excel ungroups the records. rows you want to group
Before you manually create an outline by grouping dozens of records, you should see if and select Data
Excel can automatically create the outline for you. Excel can automatically outline Group and Outline
worksheets if they contain formulas that consistently point in the same directions. Group from the menu.
Excel can automatically group and outline this worksheet since it does contain To Manually Ungroup
formulas that all consistently point to the right (the quarterly subtotals) and down (the Columns or Rows:
office subtotals).
Select the grouped
6. Click any cell in the worksheet to deselect rows 5 and 6, select Data columns or rows and
Group and Outline Auto Outline from the menu. select Data Group
Excel analyzes the formulas in the worksheet and creates an outline, as shown in and Outline Ungroup
Figure 1-28. You can still expand and collapse each group in the outline by clicking the from the menu.
corresponding Show Detail or Hide buttons, but an easier way is to use the Column
Level buttons. The Column Level buttons display or hide a specific level in your To Outline a Worksheet
worksheet. For example, if an outline has three levels, you can hide all the third levels Automatically:
by clicking the button. Select Data Group
7. Click the Row Level 2 button. and Outline Auto
Outline from the menu.
Excel displays only the first two levels in the outline—the totals for each office. You
can also hide and display columns the same way. To Remove an Outline:
8. Click the Column Level 2 button. Select Data Group
Excel collapses the outline so that only the quarterly and annual totals are displayed. To and Outline Clear
expand the outline, just click the symbol for the lowest row and column level. For Outline from the menu.
example, if there are three levels, click the button. To Hide/Display Outline
9. Expand the outline by clicking the Column Level 3 button and the Row Details:
Level 3 button. Click the group‟s Show
It‘s easy to remove an outline from a worksheet: Details button or the
10. Select Data Group and Outline Clear Outline from the menu. Hide Details button.
The outline is removed from the worksheet. Or…
11. Exit Excel without saving your changes. Click the appropriate Row
Level button or Column
Level button.
Chapter Six Review
Lesson Summary
Creating a PivotTable
A PivotTable summarizes list information dynamically, meaning once you have created a
PivotTable, you can rearrange or “pivot” it to view its data in different ways.
To Create a PivotTable: Make sure the cell pointer is located in the list and select Data Pivot
Table and PivotChart Report from the menu. Follow the on-screen instructions to create the
PivotTable.
Updating a PivotTable
A PivotTable isn‟t automatically updated if you modify its source data. You can refresh a PivotTable
by clicking the Refresh Data button on the PivotTable toolbar or selecting Data Refresh Data
from the menu.
Formatting and Charting a PivotTable
To Format a PivotTable: Make sure the cell pointer is located in the PivotTable report and click the
Format Report button on the PivotTable toolbar. Select the formatting you want to apply and click
OK.
To Create a PivotChart: Place the cell pointer anywhere in a PivotTable report and click the Chart
Wizard button on the PivotTable toolbar. You will probably have to change the chart type.
To Modify a PivotChart: Modify a PivotChart the same as you would a PivotTable—drag and drop
fields to and from the PivotTable toolbar and the PivotChart.
Creating Subtotals
To Calculate Subtotals: Sort the list, select Data Subtotals from the menu, enter the
appropriate information in the Subtotal dialog box and click OK.
To Remove Subtotals: Make sure the active cell is located within the list, then select Data
Subtotals from the menu and click Remove All.
4. You should sort a list before you group and summarize its information
using the Subtotals command. (True or False?)
6. Excel’s database functions perform calculations only for records that meet
the criteria you specify (True or False?)
Figure 2-3
A scenario is a set of values you use in what-if analysis. Imagine you are considering taking
out a home mortgage and have to determine what type of loan to take out. One scenario you
are considering is a 30-year loan with a 7.5% interest rate. Another scenario is a 20-year loan
with an 8.5% interest rate. Excel‘s scenario manager lets you create and store different
scenarios in the same worksheet. Once you have created a scenario, you can select it and
display the worksheet using its values.
In this lesson, you will use the scenario manager to perform what-if analysis on a home
mortgage. You will create three different scenarios to see how changing the amount and
length of the loan will change your monthly payments.
1. Start Microsoft Excel, open the workbook named Lesson 7A and save it
as Mortgage What-If.
If you do not know where your practice files are located, ask your instructor for
assistance.
This workbook contains information for a mortgage. To help assist you with deciding
what type of mortgage to take out, you will use Excel‘s Scenario Manager to create
several scenarios with different loan amounts and terms. The first step in creating a
Scenario is to select the cells that change.
2. Select the cell range A4:C4 and select Data What if Ananlysis
Scenarios Manager from the menu.
The Scenario Manager dialog box appears with the message ―No Scenarios defined.
Choose Add to add scenarios.‖ You want to add a new scenario.
3. Click Add.
The Add Scenario dialog box appears, as shown in Figure 2-1. You must give your
scenario a name and specify the scenario‘s changing cells, if necessary. The cell range
A4:C4 appears in the changing cells text box because you selected those cells before
you opened the Scenario Manager. First, create a scenario with the original values.
4. Type Original Quote in the Scenario name box and click OK.
Quick Reference
The Scenario Values dialog box appears, as shown in Figure 2-2 with the existing
values in the changing cells boxes. Since this is the original quote, you can save the To Create a Scenario:
scenario without changing the values. 1. Create or open a
5. Click OK. worksheet that contains
the results of one or more
The Scenario Values dialog box closes and you return to the Scenario Manager dialog
formulas.
box. Next, create a scenario with a longer loan length—30 years instead of 20.
6. Click Add, type 30 Year Loan in the Scenario name box and click OK.
2. Select Data What if
AnalysisScenarios
The Scenario Values dialog box appears. You need to change the values for this from the menu and click
scenario. the Add button to add a
7. Change the 20 in the second changing cell box ($B$4) to 30 and click new scenario.
Add. 3. Complete the Add
Excel saves the 30 Year Loan scenario and you return to the Scenario Manager dialog Scenario dialog box by
box. Create another scenario with a smaller loan amount. completing the following
8. Type Smaller Loan in the Scenario name box and click OK. settings:
The Scenario Values dialog box appears. Scenario Name: The
name for your scenario.
9. Change the 150000 in the first changing cell box ($A$4) to 125000 and
click OK. Changing Cells: The
cells that contain the
Excel saves the Smaller Loan scenario and returns you to the Scenario Manager dialog values you want to
box. You‘re ready to test your scenarios. change.
10. Select the Smaller Loan scenario from the Scenario list and click Show. 4. Click OK and enter the
The length of the loan changes to 20 years and the amount of the loan changes to values for the scenario in
$125,000. the Scenario Values
NOTE: The Scenario Manager dialog box doesn‘t close, so you might need to move dialog box.
it out of the way so that you can see the cells. 5. Click Add to add the
11. Select the 30 Year Loan scenario from the Scenario list and click Show. scenario.
Excel changes the length of the loan in B4 from 20 years to 30 years. 6. Repeat steps 4 and 5 for
each additional scenario.
Notice the monthly payment decreases from $1,162.95 to $997.95, and the Interest Click Close when you‟re
paid increases from $129,107.62 to $209,263.35. finished.
You‘re finished working with the Scenario Manager for now.
To View a Scenario:
12. Click Close to close the Scenario Manager and save your work.
1. Select Tools
Great! You‘ve learned how to use your first What-If Analysis feature. Scenarios from the
menu.
2. Select the scenario from
the list and click Show.
Lesson 7-2: Creating a Scenario
Summary Report
Figure 2-4
The Create Names dialog
box.
Figure 2-5
The Scenario Summary
Figure 2-4 Figure 2-5
dialog box.
Figure 2-6
The Scenario Summary
report.
Figure 2-6
If you‘ve defined two or more scenarios, you can summarize them by creating a scenario
summary report. A scenario summary report is a single compiled report that summarizes the
results from several scenarios. It‘s usually much easier to read a single scenario summary
report than switching between several different scenarios.
1. Select the cell range A3:F4 and select Formular Define Name
Create from the menu.
The Create Names dialog box appears, as shown in Figure 2-4. The Create Names will
automatically create range names, based on the current selection. Naming the cells will
make them easier to read when you create the Scenario Summary report.
2. Verify that the Top row check box is checked and click OK.
The Create Names dialog box closes and Excel automatically creates names for the
Name Box List selected cell range. You can verify that Excel created the correct names by clicking the
Name box arrow.
3. Click the Name Box list arrow.
The column heading names should appear in the Name Box list.
4. Click anywhere in the worksheet window to close the Name Box list.
You‘re ready to create a Scenario Summary report.
5. Select Data What if Analysis Scenarios Manager from the menu
and click the Summary button.
The Scenario Summary dialog box appears, as shown in Figure 2-5. You can create two
types of reports:
Scenario summary: Creates a report that lists your scenarios with their input
values and the resulting cells. Use this report only when your model has one set
of changing cells provided by a single user.
Scenario PivotTable report: Creates a PivotTable report that gives you an
instant what-if analysis of your scenarios. Use this type of report when your
model has multiple sets of changing cells provided by more than one user.
You will use the Scenario summary report, and it is the default option.
6. Verify that the Scenario summary option is selected, double-click the
Results cells text box, if necessary, then select the cell range D4:F4.
The Results Cells (Monthly Payment, Total Payment, and Interest Paid) are the cells
that are affected by the Changing Cells (Amount, Term, and Interest).
7. Click OK.
The Scenario Summary dialog box closes, and Excel creates a scenario summary report
on a new sheet in the workbook, as shown in Figure 2-6.
8. Save your work.
Quick Reference
To Create a Scenario
Summary Report:
1. Make sure you‟ve defined
at least two scenarios.
2. Select Tools
Scenarios from the
menu.
3. Select the type of report
(Scenario summary or
Scenario PivotTable).
4. Specify which cells you
want to include in the
report.
Lesson 7-3: Using a One and
Two-Input Data Table
400
Figure 2-7
The Table dialog box.
Figure 2-8 Figure 2-7
The completed one-input
data table with monthly
payments for each interest
rate.
Formula used to create the data table
Figure 2-9
=-PMT(C4/12,B4*12,A4)
The completed two-input
data table with monthly Column input cell—the placeholder cell
payments each interest Excel will substitute values for in the
rate and each term. formula (here, it’s the interest rate)
Figure 2-8 Values for the
column input cell
=-PMT(C4/12,B4*12,A4)
Column input cell Row input cell
Another way to get answers to your what-if questions is by using a data table. A data table is
(Not Used) Formula a cell range that displays the results of a formula using different values. For example,
Input Value Results you could create a data table to calculate loan payments for several interest rates and
Input Value Results term lengths. There are two types of data tables:
Input Value Results
Structure of a
One-Input Table
One-input Data Table: Displays the results of a formula for multiple values of a single
input cell. For example, if you have a formula that calculates a loan payment you could
create a one-input data table that shows payment amounts for different interest rates.
Formula Input Value Two-input Data Table: Displays the results of a formula for multiple values of a
Input Value Results
Input Value Results
two input cell. For example, if you have a formula that calculates a loan payment you
Input Value Results could create a two-input data table that shows payment amounts for different interest
rates and different term lengths.
Structure of a
Two-Input Table
1. Return to Sheet 1 in the 12A workbook. Click cell B7.
The first step in creating a data table is to enter the formula the data table will use.
Since you want to calculate the monthly payment of the loan based on different interest
rates, you will use the same PMT formula you created in cell D4.
2. Type =-PMT(C4/12,B4*12,A4) and press <Enter>.
Excel will use this formula to calculate values in the data table.
The next step in creating your input data table is to enter the input (in your case, the
interest rates) that you want to use into the data table. The cells in this workbook have
already been formatted with the correct number formatting, so you can enter the data
table inputs.
3. Click cell A8, type .06, press <Enter>, type .065, press <Enter>, type
.07, press <Enter>, type .075, press <Enter>, type .08 and press
<Enter>.
Since the data table formula includes a rate, or percentage, the values used in the
formula must also be a percent.
4. Select A8:A12, click the Percent Style button and click the Increase
Decimal button on the Formatting toolbar.
You‘re ready to have Excel fill in your data table using the different interest rates you
just entered in the A column.
5. Select the cell range A7:B12 and select Data What if
AnalysisTable from the menu.
The Table dialog box appears, as shown in Figure 2-7. You must specify the location of
the input cell in the Row Input Cell or Column Input Cell box. The input cell is the
placeholder cell that is referred to in the Table formula—in your case, the Interest rate,
which is located in cell C4.
6. Click the Column Input Cell box, click cell C4 (the placeholder for the
interest rate in the table formula) and click OK.
Excel fills the table with the results of the table formula with one result for each input
value or interest rate.
7. Click cell B8.
Excel has added the formula {=TABLE(,C4)} to the cell. The C4 reference refers to the
Input Cell for the formula—in this case, the interest rate.
You can also create data tables based on two input variables. For example, you can
create a data table that uses the Interest Rate as one input variable (arranged in
columns) and the Term as the other input variable (arranged in rows). The structure of a
two-input data table is slightly different from that of a one-input data table—the
formula has to be where the row and column that contain the input values intersect, in
your case, A7. You can‘t change a table once it has been created, so you will first have
to delete the current table.
8. Select the cell range B8:B12, press <Delete> to delete the data table,
and then move the formula in B7 to A7.
Now you can enter the different terms as Column Input values.
9. Click cell B7 and type 5, <Tab>, 10, <Tab>, 15, <Tab>, 20 and press
<Enter>.
Now select the data table range and open the Table dialog box.
10. Select the cell range A7:E12 and select Data Table from the menu.
The Table dialog box appears. This time, you must specify two input cells. The Row
Input Cell is placeholder cell that is referred to in the Table formula—in your case, the
Term, which is located in cell B4. The Column Input Cell will be the Interest Rate,
located in cell C4.
11. Click the Row Input Cell, click cell B4, click the Column Input Cell,
click cell C4, and click OK.
Excel computes the table using the Term (B4) as the Row Input Cell and the Interest
Rate (C4) as the Column Input cell. Compare your table to the one in Figure 2-9.
12. Save your work.
Quick Reference
To Create a One-Input
Table:
1. Set up the table area.
Make sure you include
the formula in the top row,
and the input values in
the left column.
2. Select the table range
and select Data What
if AnalysisTable from
the menu.
3. Specify the worksheet cell
you want to use as the
input value and click OK.
To Create a Two-Input
Table:
1. Setup the table area.
Make sure you include
the formula in the
upper-left cell and the
values for the first input
cell in the left column and
the values for the second
input cell in the top row.
2. Select the table range
and select Data Table
from the menu.
3. Specify the worksheet cell
you want to use for the
Row input cell and the
Column input cell and
click OK.
Lesson 7-4: Understanding Goal
Seek
Figure 2-10
The Goal Seek dialog box.
Figure 2-11
The Goal Seek Status
Figure 2-10 dialog box displays the
solution.
Figure 2-11
When you know the desired result of a single formula, but not the value the formula needs for
the result, you can use the Goal Seek feature. For example, you can afford a $1,200 monthly
payment, so how much of a loan can you take out? When goal seeking, Excel plugs in
different values into a cell until it finds one that works.
Quick Reference
To Use Goal Seek:
1. Open or create a
workbook that uses the
formulas you want to use.
2. Select Data What if
Analysis Goal Seek
from the menu.
3. Complete the Goal Seek
dialog box by specifying
which formula cell to
change, the value to
change it to, and the cell
to change.
4. Click OK.
5. Click OK to replace the
original value or click
Cancel to keep the
original value.
Lesson 7-5: Using Solver
Figure 2-12
The Solver Parameters
dialog box.
Figure 2-13
The worksheet containing
the problem to be solved
Figure 2-13 by Solver.
Changing cells Target cell
Figure 2-12 Figure 2-14
The Add Constraint dialog
box.
Figure 2-15
The Solver Results dialog
Figure 2-14
box.
Figure 2-15
Goal Seek works great for problems that have a single variable and an exact target value, but
not for complex problems that have several variables and/or a range of values. For these more
complex problems, you need to use Excel‘s Solver command. The Solver can perform
advanced what-if analysis problems with many variable cells. You can also specify
constraints, or conditions that must be met to solve the problem.
If the Solver seems especially difficult to you, you‘re not alone. The Solver is one of the most
advanced and complicated features in Excel.
The Solver is an
1. Open the workbook named Lesson 7B and save it as Annual Mail. optional add-in to
If you do not know where your practice files are located, ask your instructor for Excel. If you can’t find
assistance. the Solver Command in
This worksheet contains the problem with which you‘re faced. Imagine you‘ve been your Tools menu you
put in charge of a annual mailing campaign for existing clients in five states. Your boss will need to install it.
has given you the following budget constraints: Select Tools > Add-ins
from the menu, click
Your total budget is $35,000.
the Solver add-in
You must spend at least 50% of the budget on Minnesota mailings. check box and click
At least three mailings must go out in each state. OK.
Based on this information, your job is to find out how many mailings you can send out
to the clients in each state. Yikes! That‘s a tricky math problem! Luckily, you can use
Excel‘s Solver to help you find the answer to this problem.
2. Select Data Solver from the menu.
The Solver Parameter dialog box appears, as shown in Figure 2-12. First, you need to
specify the goal or target you want to solve. For this lesson, you want to minimize your
total mailing cost—the value in cell F7.
NOTE: If the Solver is not listed as an option under the Tools menu, you will need to
install it. Select Tools Add-ins from the menu, click the Solver add-in
check box to select it, and click OK.
3. Make sure the insertion point is the Set Target Cell box and click cell
F7.
$F$7 appears in the Set Target Cell box. Next, you want Solver to set the target cell
(the total cost) to the lowest value possible.
4. Click the Min option.
You have to be very For other problems, you might want to find the highest possible value by selecting the
precise when using the Max option. Or you might want Solver to find a solution that makes the target cell
Solver. If you don’t equal to a certain value by selecting the Value option and entering the value.
specify the proper Next, you need to specify which cells will change in order to reach the solution—the
constraint, Solver number of mailings per state.
won’t be able to find a
solution to your
5. Click the By Changing Cells box, clear any previous contents, and
select cells E2:E6.
problem (if there
indeed is a solution) or Now you‘re ready to specify the constraints Solver has to work with.
else may return invalid 6. Click the Add button.
data. The Add Constraint dialog box appears, as shown in Figure 2-14. Start by adding the
constraint that the total mailing cost cannot exceed the $35,000 budget.
7. Click the Cell Reference box, select cell F7 (the Total Cost cell), select
<=, click the Constraint box and type 35000.
Quick Reference
Compare your Add Constraint dialog box with the one in Figure 2-14. The next
To Install Solver: constraint you need to add is that 50% of the total amount must be spent in Minnesota.
Solver is an optional 8. Click Add, click the Cell Reference box, select cell F2 (Minnesota’s
Excel add-on. If you can‟t Total Cost), select >=, click the Constraint box, click cell F7 and type
find Solver under the *.5.
Tools menu you can $F$7*.5 should be displayed in the constraint box. Next, add a constraint so at least
install it by selecting three mailings must be sent in each state.
Tools Add Ins from
the menu, selecting the
9. Click Add, click the Cell Reference box, select the cell range E2:E6 (the
Solver Add-in and Number of Mailings), select >=, click the Constraint box and type 3.
clicking OK. Finally, you need to add a constraint to specify that the number of mailings is restricted
to whole numbers (otherwise, Solver will use numbers with decimal places.)
To Use Solver:
10. Click Add, click the Cell Reference box, select the cell range E2:E6 (the
1. Open or create a Number of Mailings) and select int.
workbook that contains
the problem you want to That‘s it! You‘ve finished adding all the constraints.
solve, and then select 11. Click OK.
Data Solver from the The Add Constraint dialog box closes and you return to the Solver Parameter dialog
menu. box. Let‘s see if the Solver can find a solution for this perplexing problem.
2. Specify the goal or target 12. Click Solve.
you want to solve for in
Excel analyzes the problem and plugs trial values into the variable cells, and tests the
the Set Target Cell box.
results. After a moment the Solver Results dialog box appears, indicating that Solver
3. Specify Max, Min, or succeeded in finding a solution to how many mailings you can afford to send out to
Equal to, then specify the each state, while meeting all the constraints, as shown in Figure 2-15.
cells that need to change
You have several choices here. You can keep the values from the Solver solutions, you
to meet your goal in the
can return the original values, or you can create one of three types of detailed reports
By Changing Cells box.
on a separate worksheet that summarize Solver‘s answer.
4. Add your constraints by
clicking Add and then
13. Make sure the Keep Solver Solutions option is selected and click OK.
specifying the constraints You‘ve successfully found the best combination of mailings by state using Solver. The
(repeat for as many settings you entered in Solver will be saved with the workbook, so you can easily come
constraints as you need). back to them.
5. Click Solve. 14. Save your work and exit Microsoft Excel.
Chapter Two Review
Lesson Summary
Defining a Scenario
A scenario is a set of values you use in what-if analysis, such as various interest rates, loan
amounts, and terms for a mortgage. You can save and then easily display these values once you
have saved them in a scenario.
To Create a Scenario: Create or open a worksheet that contains the results of one or more
formulas. Select Data Scenarios from the menu and click the Add button to add a new
scenario. Complete the Add Scenario dialog box giving the scenario a name and identifying the
“changing cells” (the cells that contain the values you want to change) and click OK. Click the Add
button and enter the name and changing cells for each additional scenario.
To View a Scenario: Select Tools Scenarios from the menu, select the scenario from the list
and click Show.
3. After carefully considering your budget, you decide the maximum monthly
payment you can afford is $500 on a three-year loan. Based on this
information, which feature would be the fastest and easiest way to
determine how much of a loan you can take out?
A. Goal Seek.
B. Solver.
C. Scenario Manager.
D. A Two-Input Data Table.
5. Which of the following is NOT information you can specify using the
Solver? (Select all that apply.)
A. Target cell.
B. Changing cells.
C. Constraints.
D. Input cells.
Homework
1. Open the Homework 12 workbook and save it as ―What-If Practice‖.
2. Click the Car Loan sheet tab. Select the cell range B3:B5 (the changing cells) and
select Tools Scenarios from the menu.
3. Click Add and name the scenario ―Original Loan Term.‖ Save the scenario with the
original values.
4. Click Add, and name the scenario ―9 Percent, 36 Months.‖ Save the scenario with a
$25,000 loan amount, .09% interest rate, and 36 months.
5. Practice switching between the two scenarios by selecting Tools Scenarios from
the menu, selecting a scenario, and clicking View.
6. Create a Scenario Summary report for the worksheet.
7. Click cell B11, type =B7 and press <Enter>.
8. Setup a one-input data table as follows:
9. Select Data Table from the menu and select cell B4 as the Column input cell. Your
results should be:
10. Click cell B7 and select Tools Goal Seek from the menu. Use Goal Seek to find
the maximum car loan you can take out (cell B3) if you can afford an $800 monthly
payment.
Extra Credit: Click the Solver sheet tab. Use Solver to find a solution to the
specified problem. The target cells, changing cells, and constraints are all color-
coded to make it a little easier for you.
Quiz Answers
1. D. The auto outline feature has nothing to do with what-if analysis.
2. C. Goal Seek and the Solver have target cells, but not scenarios.
3. A. Actually, you could use any of the other methods to eventually find the answer, but
Goal Seek would be the fastest and easiest in this instance.
4. True.
5. D. Input Tables require Input cells, not Solver.