MOAC Excel 2013 Lesson 9 - Working With Data and Macros PDF
MOAC Excel 2013 Lesson 9 - Working With Data and Macros PDF
and Macros 9
LESSON SKILL MATRIX
Skills Exam Objective Objective Number
Sorting Data
Filtering Data
Outlining and Subtotaling Data Create
Crea
Cr eate outlines.
te out
utliline
ut nes.
ne 2.3.5
Collapse
Collap groups
apse gro
ap roup
ro ups of data
dat
ata
at outlines.
a in o
out
utlines.
ut 2.3.6
Insert
Inse
sert
se rt subtotals.
ssubto
tota
to tals
ta ls.
ls 2.3.7
(continued on next page)
KEY TERMS
• auto-outline
• AutoFilter
• collapse
• criterion
• data file
• database
• delimiter
• filter
• grouping
• macro
• outline
• outline symbol
• parse
• quick format
• slicer
• subtotal
• table
• validation
©AlexRaths /iStockphoto
235
236 Lesson 9
You’ve been hired to keep the books at a local veterinary clinic. Its clientele is a bit
unusual in terms of bookkeeping. Although the patients have characteristics that
your co-workers need to keep track of, none of them are paying customers. Those
who pay on your patients’ behalf might be responsible for more than one patient at
a time.
Although Excel technically is not a database manager program, it’s used for data-
base management purposes in more offices than any other program. People ap-
©AlexRaths /iStockphoto preciate the convenience of keeping individual records aligned by single rows, so
everything you need to record about a certain feline or canine patient, for example,
is recorded in a single row. This way, you can have Excel sort an entire database by patients’ names or show
only certain records whose contents meet criteria that you specify (only the cats, for instance, or only the
spaniels) without disrupting the integrity of the database itself or changing the workbook.
Working with Data and Macros 237
SOFTWARE ORIENTATION
Data Tab
Most of the exercises in this lesson use the DATA tab. Although spreadsheet programs such
as Excel were originally intended to serve as calculation engines, it’s often convenient to
have recordkeeping and calculation in the same program. Although you might imagine data
entry tasks as about as dull and repetitive as a marathon of city council meetings on public
access television, Excel actually makes data easy to import from sources other than your own
fingertips, and it makes it easy to arrange and manage that data properly once you bring it
into a workbook.
Figure 9-1 Figure 9-1 shows the DATA tab on a maximized Excel window, with many of the features
The DATA tab you use in this lesson pointed out.
Sort Z to A Filter
Fi Remove
Remo
Re move
mo ve Ungroup
Ungr
grou
gr oup
ou
(Sort Largest toSmallest) columns duplicate clustered
rows rows or columns
IMPORTING DATA
When you work with a workbook that requires a large amount of data, one thing you can fervently
Bottom Line
wish for is that the data already exists in some form and that you don’t have to type it manually. If
the data you need for a workbook is sourced outside of Excel, then what Excel needs is to be able
to receive that data in such a way that it can make sense of where cells begin and end and where
records begin and end. Even simple text files where values are separated (delimited) by commas
can be imported, because commas act like fence posts, and Excel recognizes fence posts. Complex
relational databases are comprised of multiple tables, and thus can’t be imported directly. So the
trick is to be able to open a connection to the database (such as a communications channel) and
stream the specific tables you need into Excel, in a manner that Excel can readily parse (interpret
character-by-character).
GET READY. Before you begin these steps, LAUNCH Microsoft Excel.
1. If the active workbook is not a new, blank workbook, then click the FILE tab. In
Backstage, click New, and then click the thumbnail marked Blank workbook.
2. On the DATA tab, in the Get External Data group, click From Text.
3. In the Import Text File dialog box, locate and click 09 NA-EST2012-01.csv. Click Import.
4. In Step 1 of the Text Import Wizard, notice the preview at the bottom (see Figure 9-2).
This is Excel’s best guess, for the moment, as to how the data should be formatted.
There are population figures rendered in “quotation marks” with commas between
each figure. Here, each comma acts as the delimiter, and it’s difficult to judge whether
each figure between the commas will be the same length. Under Choose the file type
that best describes your data, choose Delimited, and select My data has headers.
Figure 9-2
Text Import Wizard, step 1
5. The preview shows the headers starting on row 3. Thus, for the Set import at row
option, choose 3. Click Next.
6. In Step 2 of the wizard, shown in Figure 9-3, uncheck Tab because the preview does
not indicate long spaces between the figures. Check Comma. Set Text qualifier to “
(quotation mark). Scroll down the Data preview pane, and notice now that Excel has
found the column separations between figures. Click Next.
Figure 9-3
Text Import Wizard, step 2
7. Step 3 of the wizard, shown in Figure 9-4, lets you establish the data type for each
discovered column. Click the first column in the Data preview pane. Then, under
Column data format, click Date. Click Finish.
Working with Data and Macros 239
Figure 9-4
Text Import Wizard, step 3
8. In the Import Data dialog box that appears next (see Figure 9-5), leave Where do you
want to put the data? set to Existing worksheet. Click OK.
Figure 9-5
Import Data dialog box
Figure 9-6
Freshly imported census data
worksheet
240 Lesson 9
11. Click cell A2, type April 2010, and press Enter.
12. Drag the fill handle from cell A2 down to cell A34 and release. Excel changes the
entries in column A to proper months.
13. Delete rows 35 through 40.
14. SAVE the workbook in the Lesson 9 folder as 09 Monthly Census Data Solution.
CLOSE the workbook and leave Excel open for the next exercise.
Take Note In this exercise, you use a file from Microsoft Access, although you do not need Access installed
on your computer to follow along.
Figure 9-7
Select Table dialog box
5. In the Import Data dialog box (refer to Figure 9-5), click Table. Under Where do you
want to put the data, click Existing Worksheet and ensure the text box reads =!$A$1.
6. Click OK. Excel takes a moment to query the database. Soon, it displays a fully
formatted table (see Figure 9-8), complete with AutoFilter buttons in the headers,
which you learn more about later in this lesson in “Using AutoFilter.”
Working with Data and Macros 241
Figure 9-8
Mismatched, freshly imported
XML data
CLOSE th
thee workbook
book and
workbo
wo bo nd leave
l Excel open for the next exercise.
Appending
ndin
ing
in g Da
Data
ta tto
o a Wo
Worksh
Worksheet
shee
sh eet
ee
After you
u impo
import
port
port dataa from
fr ano
another
noth
nother ffor
th format
orma
or matt or database
ma dat
d atab
at abas
ab asee into
as in a w
wor
worksheet,
orkshe you’ll probably spend a
or
good deal of time reconciling that data with existing records. In the previous two exercises, you
were lucky enough to import data into blank worksheets. In a more real-life situation, you’ll bring
data from other sources into a full worksheet and make the effort to make it fit somehow.
Troubleshooting In the course of history, the folders where old data files used to reside may cease to exist. This
is indeed the case with the original XML file from which you imported data into the work-
sheet. Some versions of the Microsoft XML parser will see this as an “error,” and others will
not. Any number of factors may contribute to which XML parser your PC actually has. In either
case, it isn’t really an error, and you don’t need to worry about it.
242 Lesson 9
Figure 9-9
Mismatched, freshly imported
XML data
5. To correct the problem, begin by moving the first names from cell range E23:E75 to
B23:B75. Overwrite the existing contents in column B.
6. Move the
he last
llas
ast names
as name
mes from
me from cell range H23:H75 to A23:A75. Overwr
Overwrite the existing
ts in
contents i column
colu
co lumn
lu mn A.
7. Repeat the
he process
pro
roce
ro cess
ce ss for
for the states
ssta
tates in column J ttha
ta that
hatt should
ha sh ld be
be in column
col E, the ZIP codes
in column
umn K tha
that
hat should
ha shou
sh ould be in colum
ou column
umn F
um F, an
and th
the phone
phonone numbers
numb
mbers in column I that should
mb
mn G.
be in column
8. Delete columns H through L.
9. Delete rows 21 and 22.
10. Replace all 11 instances of Dell City in column D with Del City.
SAVE the workbook in the Lesson 9 folder as 09 Car Owners Solution.xlsx. CLOSE the
workbook and leave Excel open for the next exercise.
Workplace Ready
WORKING WITH DATABASES
The most commonly distributed definition for the word “database” is “an organized collection
of data.” Technically, that’s wrong. If this definition was correct, any book could be a database
because books contain data—even blank books.
The reason why this matters is because you will likely acquire data from multiple sources for use
in the worksheets you produce. To be accurate, a database is anything you can use as a source for
data. When you import data from a database into an Excel spreadsheet, if that data is stored by a
relational database manager, it might not actually exist as a file yet. So the file you “import” into
Excel might communicate with the database manager to produce the data that ends up appearing
in your worksheet.
However, depending on how the database is set up, it might produce separate files that serve as
“snapshots” of the data’s state for a given point in time. When you import this type of data, you
need to know if it’s old and just how old it is. On occasion, you might not actually be able to im-
Working with Data and Macros 243
port files because the database manager program has locked them to prevent inadvertent loss of
data. In these situations, you might need to have the person overseeing the database export a sepa-
rate file for you to import. While you’re at it, you can ask for that export file to be in a regular for-
mat, such as comma-separated values (CSV) or even a worksheet format such as Excel’s old XLS.
The example you used in “Getting External Data” involves a kind of snapshot file produced by
Microsoft Access, a database manager that’s part of some versions of Office. In a real-world set-
ting, even though such a file exists, it might not always be available, for the reasons just explained.
In these cases, you need to ask for help—perhaps for someone in the IT department to produce
an export file and meet you halfway.
GET READY. OPEN the 09 Vet Clinic Patients workbook for this lesson.
1. Click the FILE tab and select Save As. SAVE the workbook in the Lesson 9 folder as
09 Vet Clinic Patients (Active) Solution.
2. Freeze rows 1 through 5 in both worksheets in the workbook.
3. In the Client list worksheet, select column L (Area Code).
4. On the DATA tab, in the Data Tools group, click Data Validation. The Data Validation
dialog box opens.
5. Click the Settings tab.
6. In the Allow list box, choose Text length. This is the first step in the creation of a rule
governing how many characters each new entry should contain. The dialog box should
now appear as depicted in Figure 9-10.
Figure 9-10
Set up validation rules for
input data
Figure 9-11
Have Excel notify the user
about your validation rule
Working with Data and Macros 245
12. Click the Error Alert tab. Excel notifies a user who missed your ScreenTip that the data
he has entered is invalid.
13. Click the Title box and type Data Entry Error.
14. Click the Error message box and type Only three-digit area codes are recognized. This
message is displayed in a dialog box whenever an invalid entry is made in column L.
The dialog box should now appear as shown in Figure 9-12.
Figure 9-12
Set up a warning for when the
validation rule is violated.
Figure 9-13
Worksheet with validation rule
enforced
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
Take Note Excel’s validation rules pertain to only new data as you enter it into the workbook, not to data that
existed in the workbook prior to creating the rules. Don’t rely on validation rules to correct errors
that might already exist, but to catch any new errors that might arise.
246 Lesson 9
$OORZLQJ2QO\6SHFLÀF9DOXHVWR%H(QWHUHGLQ&HOOV
A typical piece of information you’ll find in a database is often a single letter that represents a char-
acteristic, such as gender or political party affiliation or the work shift to which one is assigned.
In data entry, it’s easy for someone to slip and enter an invalid character. If that error isn’t caught
and the person who entered the data is replaced, would her replacement be able to rectify it? You
can preempt events like this by building a rule that restricts entry to a handful of valid characters.
Figure 9-14
Excel attempts to enforce a
validation rule.
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
Take Note It’s still feasible for an invalid value to remain in a worksheet after the user has been warned that
it’s invalid. For example, in the previous step if you were to click Yes instead of No, the value 61
would remain in column E, even though there is no client numbered 61 in column A of the Client
list worksheet.
kshe
ks heet
he et. Conceivably,
et Conc nceivabl
nc bly,
bl y, this way you can purposefully enter a new canine patient into the list
without an own wner
wn
owner,er,, if yyou iint
er nten
nt end
en
intendd to add
dd tthe owner’s
owner
er’s’s iinf
er nfor
nf orma
or mati
mation
ti
informationon later.
later
er.
er
5HPRYLQJ'XSOLFDWH5RZVIURPD:RUNVKHHW
YLQJ'
'XS
'XSOLFD
XS FDWH
FD WH5RZ
WH RZVIURP
RZ RPD:
RP :RU
:RUNV
RU NVKHHW
HW
In many databases, it’s important that each record (each row of an Excel database table) is unique.
If an entry appears twice, Excel might treat them as separate entries even if they somehow (es-
pecially by accident) contain identical information. The difficulty then comes when you try to
reconcile any other records or subsequent data that might refer to either of these duplicate entries.
As a means of cleansing your database, you can have Excel search for duplicate entries and purge
them before too much damage is done.
Figure 9-15
Remove Duplicates dialog box
248 Lesson 9
6. In the Columns list, remove the check beside Client #. If duplicate names and
addresses appear in the list, it’s likely their client index numbers were not duplicated.
7. Leave the My data has headers box checked. This way, Excel won’t treat row 5 as
though it contains data.
8. Click OK. Excel responds with a dialog box stating one duplicate value set (the one you
just entered) was removed.
9. Click OK to dismiss the dialog box. Note the second (lowermost) instance of the
duplicate entry was removed, from row 58.
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
SORTING DATA
After you enter data into a data range or, as you see later in this lesson, a formal database table, the
Bottom Line
number of the row each record appears on doesn’t matter at all. In fact, it’s important for you to
remember that data entries in Excel are not indexed by their row numbers, because they’re subject
to change. Sorting a data range helps you to locate the precise data you need. In a few respects,
it can also help Excel to look up certain data for inputs into formulas (see Lesson 5), but for the
most part sorting is for your benefit. You might want, for example, to keep people sorted in a ta-
ble by their surname rather than some arbitrary customer number you won’t remember. So when
you enter a ne neww custom omer whose
om
customer who
w hose surname begins with something earli
ho earlier than “Z,” you might
find it easierr to enter
e er the he name
namame at the
am he bottom
bot
otto
ot tom of the
to he list,
llis
ist,
is t, aand
nd then
tthe
hen
he n resort
reso
sort
sort alphabetically.
a This way,
you don’t have to to manually
manu
ma nual
nu ally
al ly insert
ertt a blank
iinser
er ank row in the
blan
an he m middle
mid dle of the
iddl
id dl the worksheet,
wor
w orks at the appropriate
alphabetical location.
locat
atio
at ion.
ion.
again, the first column you clicked in when selecting the range. Murdock the Rottweiler,
which you previously added to row 58, now appears on row 45.
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
Take Note The Sort A to Z button (also known as Sort Smallest to Largest) and Sort Z to A button (also
known as Sort Largest to Smallest) assume that the column you wish to use as your sorting crite-
rion is the one that contains the active cell. In selecting a range, whether you hold down Shift to
select the opposite corner (as you did in this exercise) or whether you drag the pointer from one
corner to the opposite corner, the (or Sort Smallest to Largest) the cell that you clicked on first.
Troubleshooting Before sorting a range, make sure you select the entire range first, including the rightmost
column(s). Excel leaves any contents outside the selected sort range exactly as they are, which
leaves you with out-of-order contents should you fail to select the entire width of the range.
6RUWLQJ'DWDRQ0XOWLSOH&ULWHULD
A proper database containing records of people divides each element of their names into, at the
very least, last and first names, and preferably includes optional elements such as middle initials
and prefixes and suffixes. For this reason, any time you sort a database, range, or table by names,
you want to sort byy multiple
ip criteria.
Figure 9-16
Sort dialog box
12. Leave My data has headers checked, so that Excel won’t treat the headers row as a
data entry.
250 Lesson 9
13. Click OK. The clients list is now sorted alphabetically, with people sharing the same
surname sorted alphabetically by first name. Although the client numbers appear all
out of sort, the data is unchanged and the database itself retains its full integrity.
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
6RUWLQJ'DWD8VLQJ&HOO$WWULEXWHV
In Lesson 6, you saw how Excel can apply special formatting to cells based on their ascertained
contents (for example, shading a temperature column extra-red when the number climbs above 90
degrees). Excel is capable of sorting records based on the conditional formatting that is applied to
their cells. This is important because Excel does not have a “conditional sort” feature, where you
create a rule or a formula that Excel evaluates to group or arrange rows. Instead, you create rules
that apply specific formats or graphics to cells based on their contents. Then Excel can sort and
group those records whose cells have these special formats applied to them.
Troubleshooting When creating a new column to the right of one governed by a data validation rule, the new
column acquires that same rule even if it’s intended for a different purpose. To clear this rule,
select the new column, bring up the Data Validation dialog box, and click Clear All as demon-
strated previously.
23. Click the down arrow next to No Cell Color. As Figure 9-17 shows, the list box that
appears shows only those colors that are actually in use for conditional formatting—in
this case, only one swatch. Click the color swatch.
Figure 9-17
Sort dialog box showing condi-
tional format color choice
24. Click OK. The sorted worksheet should now appear as shown in Figure 9-18. All the “N”
and “S” animals are grouped together at the top, with the two types mingling among
each other. All the non-operated-on animals are bunched toward the bottom.
Figure 9-18
Worksheet with conditional
format-based sort applied
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
Troubleshooting Any table you intend for Excel to sort must not contain merged cells (see Lesson 6). For Excel
to be able to exchange cell contents between positions evenly, each row must have an iden-
tical number of cells. Each of the cells in a column may be formatted differently, though their
widths may not vary.
FILTERING DATA
When you search for information online, what you expect to happen is for the search engine to
Bottom Line
return the most relevant data to your search at the top of the list. Similarly with any database,
when you make a request or a query for just the records that meet particular criteria, you expect to
252 Lesson 9
see only the relevant data, and for irrelevant or non-matching data to be filtered out. With Excel,
there’s a way for you to formally specify the boundaries of your database table—to say, “This part
of my worksheet is to be treated like a database” —and to then have Excel filter out just those
rows that don’t pertain to what you’re searching for. This does not change the database, and you
don’t delete any rows with a filter. You just hide them temporarily.
8VLQJ$XWR)LOWHU
An AutoFilter is the quickest means for you to set up a table so that it displays only rows that
meet simple criteria (for example, just the clients who live in-state, or just the clients who have
signed up for monthly newsletters). If the criteria for your search involves information that is read-
ily assessable through a simple read of the existing data in the cells, you can use an AutoFilter to set
up your search with very little trouble. There are ways for you to set up more complex, advanced
filters that replicate data to a separate location (often a new worksheet) using advanced criteria
based on formulas. But for simple assessments of the data, an AutoFilter requires much less effort.
This converts the headings row of your table into a set of controls, which you then use to choose
your criteria and select the data you want to see.
Y. USE
GET READY. USE tthe
he w
workb
kbookk fr
kb
workbook from tthe
he previou
ous exerci
ou
previous cise.
ci
exercise.
1. SAVE the
he current
cur
urre
ur rent workbook
re wor
w orkb
or kbookk as 09 V
kb Vet
et Clinic Patients
Pa (Active)
(Active
ve) Solution
ve Solu 5.
e Clie
2. Click the nt list w
ient
ie
Client workshe
heet
he et tab.
worksheet tab
ab In the
the N
Nam
ame
am
Name e bo
box,
x, ttype Cl ients and press Enter. Excel
Clie
ie
Clients
highlights the data range for the Clients table.
3. On the DATA tab, in the Sort & Filter group, click Filter. Excel adds down arrow buttons
to the field names in all of the columns in the list.
4. Click the down arrow beside the Client # heading in column A. Excel displays the
AutoFilter menu shown in Figure 9-19.
Figure 9-19
AutoFilter menu for a numeric
column
5. To sort the table by client number, click Sort Smallest to Largest. This gives you a
shortcut for sorting that bypasses the menu.
Working with Data and Macros 253
6. To show just the clients with addresses in Ohio, click the down arrow beside State. In
the AutoFilter menu that appears (shown in Figure 9-20), uncheck the (Select All) box
to clear all check boxes, and then check OH and click OK.
Figure 9-20
AutoFilter menu for a text
column
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
When an AutoFilter is active, so that you see filtered results rather than the complete table, Excel
applies special notation to the AutoFilter buttons and to the row numbers. As Figure 9-21 shows,
the button for the column used in the sort now contains a long up-arrow, whereas the button for
the column used in the filter contains a funnel symbol, like the thing you pour motor oil through.
Figure 9-21
Symbols in a filtered table
Masked row
indicators
Also, notice the row numbers are colored blue and are not consecutive. If you look closely, you’ll
see that where nonmatching rows are hidden, Excel puts a double-border between the numbers for
matching rows—for instance, between rows 18 and 21 and between 47 and 55.
254 Lesson 9
&UHDWLQJD&XVWRP$XWR)LOWHU
A custom AutoFilter uses a rule that you create, instructing Excel how to evaluate the entries in
each row. The result of that evaluation determines whether rows are displayed or filtered out.
With a simple AutoFilter, Excel looks for contents based on actual samples from the column. For
example, with the previous task, Ohio (OH) and Indiana (IN) were choices because both were
featured in the State column; no other states were listed. By contrast, with a custom AutoFilter,
you can devise a rule instructing the worksheet to display only records whose values in one given
column are above or below a certain amount. Essentially, your rule tells Excel to compare each
value in the column against something else. Whether that value is displayed depends on the terms
of the comparison—is it equal? Higher? Lower? Is it among the ten highest or lowest? The custom
AutoFilter is among Excel’s most powerful tools.
Figure 9-22
Custom AutoFilter dialog box
11. Click OK. After the dialog box disappears, Excel filters out all entries in the patient list
where the patient is known to have had a hepatitis inoculation in 2012 or later. What
Working with Data and Macros 255
remains are both the animals known to have been inoculated in 2011 or earlier, or
whose inoculation dates are not known.
12. Click the filter button beside Hepatitis inoculation again. In the menu, click Date Filters,
and then click Custom Filter.
13. In the second list box that currently reads equals, choose the blank entry at the top of
the list. The box should now be empty.
14. Click OK. The list should now show only the five animals known to have been
inoculated in 2011 or earlier (see Figure 9-23).
Figure 9-23
Worksheet with custom filter
applied
15. Click the filter button beside Hepatitis inoculation again. In the menu, choose Clear
Filter from “Hepatitis inoculation”.
PAUSE. SAVE the workbook and leave it open to use in the next exercise.
)LOWHULQJ'DWD8VLQJ&HOO$WWULEXWHV
When conditional formatting is applied to a column of cells, that formatting is something that
Excel can “get a handle on.” In other words, it’s just as good as a value in giving the filtering system
something to look for. So you can easily have a filter hide rows where cells in a column don’t have
a particular format, such as a shaded background or a font color.
PAUSE. SAVE the workbook and leave it open for the next exercise.
down items into their respective departments—for example, by listing their location on the shelf.
These descriptive categories help subdivide data into groups, and then collapse those groups into
single-row headings called outlines. Excel uses outlines to generate reports that provide you with
meaningful data about the items in each group collectively. The most important, and probably the
most frequently used of these reports shows you subtotals for the values that are grouped together.
*URXSLQJDQG8QJURXSLQJ'DWD
The simplest form of data grouping involves taking a row of cells that have one related attribute,
clustering them together, and then collapsing the cluster like a folder that can be reopened later.
The point of doing this is to reduce the size of long reports to make them easier to read. The trick
to doing this properly is leaving behind one row, after the group is collapsed, to represent the
group as a whole so someone reading the worksheet will know what to open later.
Whenever you group rows together or perform an operation (such as auto-outlining or auto-subto-
taling) in which groups are automatically created, Excel adds controls next to the row and column
headings. Excel calls these controls outline symbols.
Boxes marked with minus and plus symbols are placed at the bottom of grouped rows or to the
right of grouped columns. Each one acts like a clasp that can collapse or expand the group’s con-
tents. In the up
uppeper left
pe
upper ft corner
cornenerr are
ne ar number buttons that let you show or hide hi all of the group con-
part
rtic
rt icular level.
ic
tents for a particular llev
evel. When
ev When yyouou have
hav
h avee two groups
av grou
oups
ou ps ttha
hatt are
ha
that are just
ju beside
bes
esid
esid one another, you have
only two levels:
s: the
els: he collapsed
ccol
olla
ol laps
la ed view
psed
ps w and
an the
the expanded ed one.
o But Bu youyou ca
can have groups within groups,
n ha
and for each grouping
gro
roup
ro ing level
upin
up in leve
le vell you
ve yo crcreate,
crea
eate, Ex
ea Excel
cel adds another
Exce ano
noth
no ther n
th number to this bank of outline symbols.
Take Note The rows and columns that you enroll into a group should be those that you do not want to see
when the group is collapsed. Field name rows that identify cells and total rows that include subto-
tals should not be included in groups.
Take Note Enrolling a set of records into a group changes the behavior of AutoFilters that might incorporate
that group. For example, when you try to sort a column, only the records that are not members of
a group are sorted. Once records are grouped, their order is fixed and their usefulness as parts of
an active database is reduced, especially if you add subtotal rows to the middle. For this reason,
you should reserve grouping and outlining for workbooks that are presented as final (unchanging)
reports for a particular point in time.
2. With the Patient list worksheet active, on the DATA tab, in the Sort & Filter group, click
Clear.
3. Next to Cat or Dog?, click the down arrow button. In the menu, click Sort A to Z. Now,
all the cats are clustered together at the top, and dogs at the bottom.
4. Right-click the heading for row 30, the row where the first dog appears. Click Insert in
the shortcut menu.
5. Select cell H30. Type Number of cats.
6. Select cell G30. On the HOME tab, in the Font group, click the Bold button. This makes
this particular number stand out.
7. On the HOME tab, in the Editing group, click the AutoSum down arrow. In the menu,
click Count Numbers, and then press Enter. Excel inserts a function into the cell
that counts the number of contiguous cells in the column just above it that contains
numbers—in this case, the owner numbers for clients.
Working with Data and Macros 257
8. Add a similar function for counting the number of dogs to row 60. (Bypass the
validation rule by clicking Yes in the dialog box.)
9. Select rows 6 through 29 (all the cats).
10. On the DATA tab, in the Outline group, click the Group button. A group indicator line is
added to the left of the row markers and an outline symbol on the row just below the
end of the group (see Figure 9-24).
Figure 9-24
Worksheet with
Outline level
groups applied buttons
Outline symbol
Another Way
To collapse all the
groups in a worksheet, select 11. Repeat the process in Steps 9 and 10 for the dogs in rows 31 through 59. Format cell
the entire worksheet first, G60 as Bold. In cell H60, type Number of dogs.
and then click Hide Detail 12. To collapse the cats group, click the minus box (shown in Figure 9-24) beside row 30,
in the Outline group of the which contains the cats count. The control becomes a plus box, indicating that when
DATA menu tab. To expand all you click on it, it expands to show hidden rows.
groups, click Show Detail.
13. Collapse the dogs group with the minus box in row 60. The worksheet now appears
fully collapsed (see Figure 9-25).
Figure 9-25
Worksheet with collapsed
groups
14. Click the Select All button. On the DATA tab, in the Outline group, click Show Detail.
15. Select columns B through F.
16. In the Outline group, click the Group button. A new column group is created.
17. Click the minus box over column G to collapse the column group. Click the plus box
that takes its place to expand it.
18. Select columns B through G.
19. In the Outline group, click the Ungroup button. The columnar group disappears.
258 Lesson 9
SAVE and CLOSE the workbook. Leave Excel open for use in the next exercise.
$XWR2XWOLQLQJ'DWD
Grouping data is an easy process when you have only a few groups in your worksheet that really
matter, such as cats and dogs. For a complex report, such as a balance sheet with assets and liabil-
ities broken down into departments and sub-departments, the task gets much more tedious. For
this reason, Excel has offered to make things somewhat simpler. Suppose you inserted total value
cells along the bottom rows of related cells, or along the right column beside related cells—or
perhaps both. You probably need to do this anyway for a formal balance sheet, or for a table with
names of salespeople in rows and sales for days of the week in columns—here, you total for each
salesperson along the right column, and for each day along the bottom row. Excel can detect when
and why you set up your worksheet like this, so when you auto-outline a table or a worksheet
full of tables, it creates the groups automatically and spares you the trouble.
GET READY. OPEN the 09 Critical Care Expenses workbook for this lesson.
1. SAVE the
he w
workboo
workbook
ook in tthe
oo he Lesson 9 folder as 09 Critical Care Exp
Expenses 0315 Solution.
2. Select cel
cell
ell H1
el H18. On the he HOME
HOM
H OME
OM E tab,
b, in
n the Font
nt g
gro
group,
roup
ro up,, cl
up clic
click
ickk th
ic the Bo
Bold button. Then, in the
Editing group,
grououp,
ou p, cclick
ck tthe
he Auto Sum b
AutoSum
toSu button
but
utton and
d pr
pres
press
esss Enter
es Enter. r. Th
Thee grand
gran total appears as
cell
ce ll.
ll
bold in the cell.
3. Repeat the grand
gra
rand total
ra tot
otal proce
ot process
cess
ce ss for
or ccel
cell
elll H2
el H288 an
andd apply
appl
ap ply
pl y Bold
ld tto
o the cell.
2.3.5
4. Select the cell range B10:H28, covering both groups of expenses in their entirety.
5. On the DATA tab, in the Outline group, click the down arrow next to Group. In the
How do you create outlines? menu, click Auto Outline. As Figure 9-26 shows, Excel automatically groups rows 12
through 17 and rows 22 through 27, having spotted the Total Expenses row along the
bottom of each cluster. Excel also groups together the columns for March 15 through
19, having spotted the weekly totals columns along the right.
Figure 9-26
Outlined worksheet
SAVE the workbook and LEAVE Excel open for the next exercise.
Working with Data and Macros 259
&ROODSVLQJ*URXSVRI'DWDLQDQ2XWOLQH
When you create an outline around groups of data in a worksheet, outline symbols appear for each
group of rows and columns. You use these devices to collapse and then expand the outline, thus
switching between summary and detailed views of the worksheet.
Figure 9-27
Outlined worksheet with
collapsed groups
2. Click any of the plus boxes (which replaced the minus boxes) to expand the group to
which it’s attached.
3. To remove the outline entirely, on the DATA tab, in the Outline group, click the Ungroup
2.3.6 button arrow. In the menu, click Clear Outline.
SAVE and CLOSE the workbook. Leave Excel open for the next exercise.
How do you collapse groups
of data in an outline?
6XEWRWDOLQJ'DWDLQ2XWOLQHV
Suppose a worksheet serves as a report of certain activity that takes place on given days with re-
spect to specific divisions of the company in particular regions of the country. These three catego-
ries represent levels of information. When you sort a worksheet so that these levels are in a precise
order, as you’ve already seen how to do, then Excel can accept each of these levels as tiers in an out-
line. An outline gives you the complete summary while hiding the details until you request them.
GET READY. OPEN the 09 Server Usage Stats workbook for this lesson.
1. SAVE the workbook in the Lesson 9 folder as 09 Server Usage Stats 130831 Solution.
2. Select the range A5:G140.
3. On the DATA tab, in the Sort & Filter group, click Sort.
260 Lesson 9
4. In the Sort dialog box, in the Sort by line, choose Date, Oldest to Newest. Click OK.
2.3.7 5. On the DATA tab, in the Outline group, click Subtotal. The Subtotal dialog box appears.
6. In the At each change in list box, click Department.
How do you insert 7. If necessary, in the Use function list box, choose Sum.
subtotals?
8. In the list of columns marked Add subtotal to, select the boxes for Avg. Bandwidth,
Data In, Data Out, and Transactions.
9. Check the Summary below data and Replace current subtotals check boxes, if
necessary. The dialog box should now appear as depicted in Figure 9-28.
Figure 9-28
Subtotal dialog box
10. Click OK. Excel inserts subtotal rows for each company division, grouping together
data consumption values for all three corporate regions. It places each of these division
row clusters into groups. It then creates a broader group for the entire range and adds
a grand total row at the bottom. The result is a subtotal-endowed worksheet with a
three-tier outline (see Figure 9-29).
Figure 9-29
Automatically subtotaled
worksheet with three-tier
outline
SAVE and CLOSE the workbook. Leave Excel open for the next exercise.
Working with Data and Macros 261
Take Note When you remove an outline from an automatically subtotaled range, the subtotal rows that Excel
inserted automatically remain. So to return a worksheet to its pre-subtotaled state, you must delete
each subtotal row manually.
)RUPDWWLQJD7DEOHZLWKD4XLFN6W\OH
Let’s be honest: Big worksheets are hard to read. When you look at a well-laid out document that
contains a ttab
table
able full
ab ulll of figures,
ful
ul figu
gure
gu res, you can see how typesetters apply graph
re graphic tools to make the table
easier to re
read—tools
read
ad—t
ad —too
—t ools
oo such
ls suc
uch
uc alternating
h as altlterna
lt nati
na ting
ti ng bands ds across
aacr osss every
cros
cr os ever
ev otherr line.
eryy ot
er line You can (meticulously)
li
apply such
ch a style
sty
tyle
ty le to normal
to a no
normrmal range,
rm ange, but
rran
an bu what wouldwou
ould
ou happen
ld h
hapappen when
ap when you sorted the range? The cell
ng would
formatting wou
w ould
ou ld move
mov ovee al
ov along with
wi the he cells, and d yo
your alternatingng bands would be jumbled up. By
denoting which ch part of a wor worksheet
orks
or kshe
ks heet iiss a table,
he tabl
ta ble,
ble, E
Exc
Excel
xcel
xc el ccan
an apply
a ly some
ssom
ome formatting
om fo independently of
contents. So a properly banded table stays properly banded when you sort the table, or when you
insert and delete rows.
GET READY. OPEN the 09 Pet Pharma Sales workbook for this lesson.
1. SAVE the workbook in the Lesson 9 folder as 09 Pet Pharma Sales August Solution.
2. In the August Sales worksheet, select the data range A6:K93.
3. On the HOME tab, in the Styles group, click Format as Table. Excel brings up a colorful
menu full of sample layouts (see Figure 9-30).
Figure 9-30
Table format menu
3.2.1
4. Click the sample in row 4, column 7 (Table Style Medium 7). The Format As Table
dialog box appears (see Figure 9-31).
Figure 9-31
Format As Table dialog box
Take Note You can change the format of a table at any time using the Format as Table command. You only
see the Format As Table dialog box the first time you format a table, which effectively changes a
standard range to a table. Afterwards, you only need to select a cell inside the table to tell Excel
which table you want to reformat.
5. Because the cell reference under Where is the data for your table? is accurate, don’t
3.2.2 make any changes and click OK. Excel converts the data range into a formal table and
applies the style you chose, which includes automatically banded rows that maintain
How do you band rows and ndin
nd ing even
in
their banding en when
whe
hen
he n rows become sorted. AutoFilter controls
control are also added to the
columns? ames
am es row.
field names row
ow.
ow
6. To automatically
omat
atic
at ical
ic ally
al ly boldface
bol
b oldf
ol dfac
df ace th
ac thee righ
rightmost
ghtm
gh tmost colu
column
lumn
lu mn in
in the table
tabl
ta ble
bl e (T
(Total Sales), click any
cell inside
ide the
the table.
ta e. On O the e DESIGN
DE GN tab, in the he Tablele Style
le Options group, click Last
mn.
Column.
Take Note The Table Style Options group also contains an option for banding columns instead of rows.
Uncheck Banded Rows from this group, and then check Banded Columns.
SAVE the workbook and LEAVE it open for the next exercise.
Take Note When you scroll down a data table so that the field names row disappears, as long as the active cell
stays within the table area, the usual column headings (A, B, C, and so on) are replaced with the
complete field names, as Figure 9-32 depicts. The AutoFilter buttons also move to the headings
row. This way, you don’t need to freeze the field names row in place to keep the names themselves
visible. When you move the active cell outside the table area, the standard column headings re-
appear.
Figure 9-32
Field names display in the
headings row.
5HPRYLQJ6W\OHVIURPD7DEOH
If you’re at a point where you want to create a custom style for your table, or for multiple tables in
your workbook, you might want to begin by removing the formatting that’s already present. The
table style removal feature in Excel is a bit buried and needs to be uncovered to be used.
Working with Data and Macros 263
Figure 9-33
Table Styles menu on the
DESIGN tab
Troubleshooting There are two places to find the table styles menu in Excel. One is under the Format as Table
button on the HOME tab. The other is in the Table Styles group of the DESIGN menu tab. At
first, both menus look the same. But only the one on the DESIGN tab has the Clear button to
remove styles from a table.
5. To change the table style to something that contrasts against the others in this series,
bring up the Quick Styles menu again, and this time, choose Table Style Light 6 (upper
right corner).
6. To automatically apply boldface to the rightmost column, in the Table Style Options
group, ensure Last Column is checked. To do the same for the leftmost column, check
First Column.
SAVE the workbook and LEAVE it open for the next exercise.
'HÀQLQJD7LWOHIRUD7DEOH
Up to now, you’ve seen some nuanced and subtle differences between tables and ordinary data
ranges. The one big difference between the two lay with the table’s ability to be given a title, so
that it and its constituent columns can be referred to by name instead of by reference location.
This changes everything when you write formulas that refer to parts of the table, because now you
don’t have to know where they’re located, just what they’re called.
264 Lesson 9
Once a table is given a title, all the names of its columns can be used in place of cell references in
a formula. The result is not only a formula that’s easier to conceive, but easier to read and even
easier to type. So instead of an absolute cell reference such as $B$2:$B$55 (which starts on the
second row, of course, because the headers are always on the first row), you can use a reference such
as Inventory[Sale Price]. Excel already knows not to treat the first row as values, and whenever
records are added to the table, the results of the formula are adjusted without the formula itself
even having to change its appearance.
TableName[FieldName]
Component Meaning
FieldName The field name from the header row of the table. The name refers
to the set of all cells that comprise the named name column in the table.
You do not need
Yo d to sspe
peci
pe cify
ci
specify fy the
he start
ssta
tart and
ta nd end
e cell. The field name is
always
ys d
denoted w withh [s
[squ
quare br
qu
[square brac
acke
ac kets
ke ts].
ts
brackets]. ].
Exam
ampl
am ples: Surnam
Examples: ame,
am
Surname, e, IIssue
ue date, Sal ale price
al
Sale
Note: Excel recognizes four constants that refer to the same general area of a table, which you may
use here when applicable to replace the field name:
#Data The set of all cells that contain data, excluding the header row at
the top and any total or subtotal rows that might appear at the
bottom
#Headers The set of all cells in the first row in the table
#Totals The set of all cells where totals appear, usually the rightmost col-
umn of the table where a SUM function is employed
When you type a table-style reference inside a formula, Excel gives you a shortcut. After you type
the second character of the table name, Excel displays a list of names you can add to the formula
(including named ranges). Figure 9-34 shows you what it looks like. Instead of typing in the rest
of the name, you can use the arrow keys on the keyboard to navigate this menu until the name
you want (the table name) is highlighted, and then you press Tab. The entire name is entered into
the formula, saving you a few seconds of time.
Figure 9-34
IntelliSense menu for the
table name Menu pops up here
With the table name entered, when it’s time to refer to a field name in the table, you can start with
the left square bracket ( [ ). Excel displays a list of all the field names already in the table. You use
Working with Data and Macros 265
the arrow keys to highlight the one you’re looking for, and then press Tab. Then type the right
square bracket ( ] ) to complete the reference.
Similarly, whenever you want to use one of the four constants (#All, #Data, #Headers, or #Totals),
you just start with the pound sign #. Excel displays the list, and then you highlight the one you
want and press Tab. Microsoft markets this feature as IntelliSense, and you see it referred to as such
in the Help system.
Troubleshooting When you highlight the entry you want on the IntelliSense menu, make sure to press Tab, not
Enter. The Enter key tells Excel the formula is complete, and at this point, it’s often not.
Take Note When referring to a field name by name in a formula that’s used inside the same table as the field
name, you can omit the table name. For example, the reference Customers[Surname] can be sub-
stituted with just Surname when the reference is inside the Customers table.
SAVE the workbook and leave it open for the next exercise.
3.2.3 GET READY. USE the workbook from the previous exercise.
1. Select any cell in the table. Excel adds the DESIGN tab to the ribbon.
How do you insert total 2. With the August Sales worksheet active, on the DESIGN tab, in the Table Style Options
rows in a table? group, select the Total Row box. Excel adds a total row to the bottom, as shown in
266 Lesson 9
Figure 9-35, with a label in the leftmost column and the grand total in the rightmost
column.
Figure 9-35
Total row added below table
Total row
3. To add other
oth
ther
th er subtotals
sub
ubto
ub tota
to tals
ta ls or formulas
form
fo rmulas
rm as to
t the Total
Tota
tall Row,
ta Row, you can
can choose
ccho
ho one from a drop-
down menu. u. Click
Cli
C lick
li ck the
the cell in the
t total
tot
otal
ot al row at th
the bo
bott
ttom off the
tt
bottom th Item Price column.
4. Click the
e down
wn arrowow that appears
appe
ap pear
pe arss to the
ar the rrig
right
ight
ig ht o
off th
thee bl
blankk cell.
ce In the popup menu (see
Figure 9-36), click Average. Excel calculates the average price per sales item.
Figure 9-36
Adding formulas to the
total row
5. Repeat the process to find the maximum number of items sold in one order by
choosing the Max function for the No. Sold column.
SAVE the workbook and leave it open for the next exercise.
Working with Data and Macros 267
$GGLQJDQG5HPRYLQJ5RZVRU&ROXPQVLQD7DEOH
Databases are never finished. When you maintain data in an ordinary range, one problem you
frequently face is how and where to insert a new row. There’s no rule that says you have to insert
a new record in alphabetical order, when the range is sorted alphabetically. You can add it to the
end and sort again. Here’s the problem: If you’ve named your range already, when you add the
record to the end, you might need to reassign the range name. With a formal table, not only does
the range for the table stay named properly, but when you insert rows (as well as delete them) the
named range covered by the table is adjusted to fit automatically. And any formulas you use inside
each of the rows in the table are copied and adjusted to the new rows you add.
Figure 9-37
Appended column to a table
Take Note Excel doesn’t apply its autofill IntelliSense feature for table field names while you enter data out-
side the table.
19. Rename
me tthe
he new
ew c
col
column
olum
ol umn % of Avg
um Avg.
vg.
vg
20. Select cell ra
rang
range
nge L7
ng L7:L
L7:L9393 and
:L93
:L nd g
give th
thee range a pe
perc
percent
rcen
rc ent style.
en e. EExc
Excel
xcel does not
xc
automatically
ticalllly
ll y co
copy custom
py cus
ustom ce
us styles
cell sty
tyle
ty les down
wn a ccolumn, n, so yo must select the range
you mu
manuallyly firs
rst.
rs
first. t. Note
e ho
how ExExce
cel ha
ce
Excel hass mo
move
ved
ve
moved d th
thee la
last
st ccol
olumn’
ol n’ss bo
n’
column’s bold
boldfaced format from
Total Sales to % of Avg.
21. Click any cell in % of Avg., and then click the down arrow next to Delete. Click Delete
Table Columns. As the appended column disappears, the boldfacing is returned to
Total Sales.
SAVE the workbook and leave it open for the next exercise.
Figure 9-38
AutoFilter menu for records
in a table
Another Way
A quick way to
filter a column by the contents
of one of the visible cells in
3. Leave the choices set at Top 10 items, and then click OK. The table is filtered down to
that column is to right-click
the 10 items with the highest sales.
that cell, click Filter in the
menu, and then click Filter by SAVE and CLOSE the workbook and leave Excel open for the next exercise.
Selected Cell’s Value.
Figure 9-39
Changed and unchanged
filtered table
Troubleshooting The exceptions to the rule about references to a table outside a filtered table are the # con-
stants. If the formula in cell D98 of the example is =SUM(DrugSales[#Totals]) instead of
=SUM(DrugSales[Total Sales]), the formula would adjust itself to tally only the visible, filtered
records.
270 Lesson 9
6RUWLQJ'DWDRQ0XOWLSOH&ROXPQVLQD7DEOH
With a table, as with an AutoFiltered range, you can apply a filter and a sort order at the same
time; for instance, you can show only the records that contain a particular entry (all motorcycles,
all dogs, and so on), sorted in alphabetical order by name.
GET READY. RE-OPEN the 09 Car Owners Solution workbook from earlier in this lesson.
1. SAVE the workbook in the Lesson 9 folder as 09 Car Owners Solution 2.
2. Select the range A1:G73.
3. On the HOME tab, in the Styles group, click Format as Table. In the menu, click Table
Style Medium 14.
4. In the Format As Table dialog box, click OK.
5. Because this range contains data appended from an outside source (see the
3.3.2 “Appending Data to a Worksheet” section earlier in this lesson), the query data related
to that outside source is still attached to the range. Click Yes in the dialog box to have
How do you sort data on Excel remove those connections.
multiple columns in a table? 6. Click the
e Na
Name b
box
ox and
nd rename
r the table Owners.
7. Resize col
columns
olum
ol umns
um ns B
B,, E, an
andd F tto
o more
re appropriately
appropria
a iate
ia tely
te ly fit
fit th
thei
their
eir co
ei conten
contents.
ents
en
8. Change the
he font
ffon
ontt fo
on for th
thee enti
entire
tire
ti re table
le to
t Cambri a, 11 p
Cambria,
ria pt.
9. Left-justify
tify column
ccol
olumn
ol nGG..
10. With the Owners table selected, on the DATA tab, in the Sort & Filter group, click Sort.
The Sort dialog box appears (refer to Figure 9-16).
11. In the Sort by list box under Column, choose Last Name.
12. Click Add Level.
13. In the Then by list box that appears under Column, choose First Name. Click OK.
SAVE the workbook and leave it open for the next exercise.
SAVE the workbook and leave it open for the next exercise.
Working with Data and Macros 271
5HPRYLQJ'XSOLFDWHVLQD7DEOH
When you import data and append it to the end of an existing table or range, you might end up
with duplicate entries—cases where a person appears twice, or perhaps more. Rather than go
through the list by hand, Excel has a way to excise duplicate entries from a table more intelligently.
GET READY. RE-OPEN the 09 Pet Pharma Sales August Solution 4 workbook for this
lesson.
1. SAVE the workbook in the Lesson 9 folder as 09 Pet Pharma Sales August Solution 5.
2. On the DATA tab, in the Sort & Filter group, click Clear. Click any cell inside the table.
3. On the DESIGN tab, in the Tools group, click the Insert Slicer button.
4. The Insert Slicers dialog box contains empty check boxes for each of the fields for
which you can create buttons (see Figure 9-40). Click For use on and To treat.
272 Lesson 9
Figure 9-40
Insert Slicers dialog box
Figure 9-41
Worksheet with slicers added
8. To see just the treatments that apply to dogs only, click Dog on the To treat slicer. Note
that the AutoFilter button for the To treat column shows a filter has been applied.
9. To show just the treatments that apply to the endocrine system, click Endocrine on the
For use on slicer. Note that the filters from both slicers apply simultaneously, so you
should see endocrine system treatments for dogs only. The slicer highlights only the
criterion in use for the current filter.
10. To clear the filters using the slicers, click the Clear Filter button in the upper right
corner of each slicer.
SAVE and CLOSE the workbook and leave Excel open for the next exercise.
Working with Data and Macros 273
Troubleshooting When an AutoFilter button for a column is used to filter a table and a slicer exists for that
same column, the slicer shows the criteria currently in use for that filter. However, the Clear
Filter button for the slicer is disabled. To clear this filter, you have to use the AutoFilter button.
GET READY. RE-OPEN the 09 2005 Customers Solution workbook for this lesson.
1. Near the top of the Excel window, respond to the security warning by clicking Enable
3.1.1 Content.
2. SAVE
VE tthe
he wor
workbook
orkb
or kbook in the Lesson 9 folder as 09 2005 Customers
kb Customer Solution 2.
How do you move between 3. Click an
any ce
cell
ll iins
inside
nsid
ns ide
id e the
th table.
tabl
ta ble.
bl
tables and ranges?
4. On the
he DESIGN
DES
D ESIG
ES IGN
IG N tab,
tab, in the
th Toolss gr
group, cli
click
lick
li ck Co
Convert
Conv
nvert to Ran
nv Range.
ange
an
5. Excell opens
open
ens a dialog
en dial
alog box
al ox tto
o veri
verify
rify
ri fy tthi
this
hiss co
hi conv
conversion
nver
nv ersi
er sion
si on is what
what you
y want. Click OK. The
AutoFilter buttons are removed from the header row and entries are left sorted as they
were. Subtotals and total rows remain (if applicable), and formatting is left as it was.
The DESIGN tab is no longer displayed.
SAVE and CLOSE the workbook and leave Excel open for the next exercise.
5HFRUGLQJD%DVLF0DFUR
What makes a recorded macro useful is the fact that it can be replayed on whatever cell is the
active cell. A recorded macro is a series of steps that can be repeated and that you might want
to repeat frequently to save you time. As you’ve seen, there are ways to automate the formatting
of cells that are actually easier than recording and playing back macros. So the kinds of steps you
want to record are the repetitious kind that you would otherwise have to repeat yourself dozens
of times or more.
Troubleshooting Excel records only those steps that have a direct impact on the contents of the worksheet. To
be accurate, it records the impact those steps have, not actually the commands that led to the
impact. For example, if you select several rows and columns, Excel records the act of the rows
and columns being grouped. But if you expand or collapse that group, it does not record that
fact because doing so does not impact the worksheet itself. Exceptions include filtering and
sorting ranges and tables, which Excel does record.
274 Lesson 9
Workplace Ready
PLANNING TO RECORD A MACRO
To ensure that the macro you record is useful to you in a variety of situations, you should consider
whether you need it to record absolute or relative cell references. This is because Excel keeps track
of every change in the position of the active cell during macro recording. When that change is
made, Excel needs to know whether it’s more important for it to know the exact address of the
new cell’s location (absolute) or the number of cells left or right or up or down that the pointer was
moved from its previous location (relative).
When you’re recording absolute references, record a macro, and then click on cell A5, the record-
ing always moves to A5. But if you use the arrow keys on the keyboard to move to another cell
instead, the recording takes note of each arrow key pressed. So if you record the macro on A5 and
use the down arrow key to move two cells down, and the macro replays from cell Y5, the macro
moves to Y7.
By comparison, when you record relative references and then click a new location on the work-
sheet, Excel records the distance to the new cell. This makes the starting cell location critical to
the macro. If yo
you start with a cell selected in column D,, and you yo click on a cell on the same row
in column A, Exc
Excel
xcel records
xc rec
ecor
ec ords a movement
or mov
m ovem
ov ementt th
em three cellss to the left.
the llef
eft.
ef That
t. T
Thahat is no
ha not the same thing as mov-
ing to the leftmost
eftm
tmos
tm column,
ost co
os colu
lumn
lu mn,, which
mn whic
wh ich you no
ic normally can an do by pre pressing
ress
re ssin
ssingg th
in the Home key. However, in
ording
ng m
relative recording mod
ode,
od
mode,e, ppre
ressingg Ho
re
pressing Home
me rec
ecords the
records he distance
dis
d ista
tanc
ta nce covered
nc cove
vered
ve d in getting to column A. So
when you replay
eplay th
this mac
macro,
acro
ac ro, you
ro u co
could en
end
d up ssta
starting
tart
ta rtin
rt ingg in a cell
in c in ccol column
olum F and end up moving
ol
to column C when you expect to move to column A. Or, you can start in column B and trip an
error condition when Excel tries to move too far to the left of column A.
For this reason, it’s important to map out your precise cell movements (if any) prior to recording a
macro, and then slowly repeat that sequence during the recording process. The recording does not
account for how much time you take, so if you’re nice and slow, the playback won’t be any slower.
Working with Data and Macros 275
GET READY. OPEN the 09 4Strong Tour Revenues workbook for this lesson.
1. Click the FILE tab, and then click Options.
2. In the Excel Options dialog box, click Customize Ribbon.
3. In the Main Tabs list on the right, check the Developer box if it is not already checked.
This adds the DEVELOPER tab to Excel, enabling you to record macros. Click OK.
4. The macro that you record creates a custom subtotal row at the place you define,
rather than at some place Excel determines. The rule you follow is that the user (you)
must select the cell where you want the subtotal to appear, and then run the macro. So
to prepare for recording, click cell D21.
5. On the DEVELOPER tab, in the Code group, find Use Relative References. If it is not
highlighted, click to select it. You want relative references for this macro.
6. In the Code group, click Record Macro.
1.4.12
7. In the Record Macro dialog box, click the Macro name box and type CustomSubtotals.
8. In the Shortcut key box beside Ctrl +, type the capital S. This changes the shortcut key
How do you assign a to Ctrl + Shift + S. Leave Store macro in set to This Workbook. The dialog box should
shortcut key? now appear as depicted in Figure 9-42.
Figure 9-42
Record Macro dialog box
Troubleshooting If you mess up a step during the macro recording, don’t worry. Click Stop Recording in the
Code group of the DEVELOPER tab. Then start again from Step 6. Use the same name, and
when Excel asks whether you want to overwrite the existing macro with the same name, re-
spond with Yes.
22. Now that you’re not recording, adjust the width of column E to fit its contents. As
Figure 9-43 shows, the macro generates a total for the bottom of the arbitrary cluster
of records, and also tabulates the highest value in that cluster in the cell adjacent to the
subtotal.
Figure 9-43
Custom subtotals generated
with macro
Custom subtotals
generated with macro
Another Way
In the green status
bar along the bottom of the
Excel window, there’s an icon 23. Click the
e FI LE tab
FILE tab,
ab, and
ab an then
then click
cli
lick Sa
li Save
ve As.
that looks like a worksheet
24. In Backstage,
kstage
ge,, locate
ge loca
lo cate
ca te the
the Lesson
Les
esso
es son 9 fo
so folder.
with a dot in the upper left
corner, as shown in Figure 25. In the Save
ave As dialog
dialo
log
lo g box, u
und
under
nder S
nd Sav
Save
ave as ttyp
type,
ype,
yp e, choos
choose
ose Exce
os Excel
cell Macro-Enabled
ce Macr Workbook
9-44. Click this to bypass the m)
(*.xlsm).
ribbon and immediately start
recording a new macro. Click SAVE the workbook as 09 4Strong Tour Revenues Solution.xlsm and leave it open for the
the same spot again to stop next exercise.
recording.
Figure 9-44
Alternate record macro button
Record macro
For security reasons, Excel no longer saves macros in its regular .XLS and .XLSX files. This is
due to how often the macros feature was maliciously used by people sending Excel workbooks to
others via e-mail attachments. Now, the only way to save a macro-enabled workbook is to give it
the special .XLSM file type. This way, companies that want to avoid any possibility of spreading
malware can enforce policies preventing .XLSM files from being attached to or received within
e-mails.
5XQQLQJD0DFUR
A recorded macro follows the steps you gave Excel during the recording process. For that reason,
it’s up to you to prepare the worksheet and select the cell you want before you begin. You can play
back any macro by selecting it from the Macro dialog box. But it’s generally easier to assign it to a
keystroke, as you did in the previous exercise, and simply launch it from the keyboard.
Working with Data and Macros 277
SAVE the workbook and leave it open for the next exercise.
0DQDJLQJ0DFUR6HFXULW\
Because of the proliferation of malicious software, Microsoft has set up Excel so that after it’s
installed, you cannot execute macros from a file you open (even an explicitly macro-enabled work-
book) until you read the notification and click Enable Content. If you never plan to run macros
or if you’re skeptical about your office colleagues, you can turn off macros completely. You can
also turn off the notifications and enable all macros, if you work in an office such as a financial
services provider
pro
provi
ro vider wh
vi macros
where ma
macrcros are in use constantly, you trust the source
cr sour of the Excel workbooks,
and notifications
ficat
fic atio
at ions would
io wou
would only
ou nly get
oonl
nl he way.
get in tthe
Figure 9-45
Trust Center with macro
protection settings
3. Click OK.
SKILL SUMMARY
Objective
In this lesson you learned how: Exam Objective Number
Knowledge Assessment
Multiple Choice
Select the best response for the following statements.
1. Which of the following procedures is not a way to sort a table by the contents of one
column?
a. Click the Sort button in the Sort & Filter group of the DATA tab.
b. Click an AutoFilter button in the total row.
c. Click an AutoFilter button in the field names row.
d. Click the Filter button in the Sort & Filter group of the DATA tab.
Working with Data and Macros 279
True / False
Circle T if the statement is true or F if the statement is false.
T F 1. You remove duplicate rows from a table the same way you would for a named
range of AutoFiltered records.
T F 2. You cannot sort a table in alphabetical or numerical order for one column and
by conditional formatting for another column at the same time.
280 Lesson 9
T F 3. When importing data from a text file, you can tell Excel to recognize a character
other than a comma as a field delimiter.
T F 4. You can have no more than two criteria in a custom AutoFilter.
T F 5. Immediately after you group together a cluster of adjacent rows, Excel prompts
you to create a total row beneath it.
T F 6. Once you remove an automatic style from a table, it is no longer a table.
T F 7. The title given to a table appears above the field names row.
T F 8. The @ character is required before any reference to a specific value in a named
row.
T F 9. Field names in a table, as opposed to a named range, must begin with an
alphabetic character.
T F 10. Excel will not let any macro run in a worksheet without the user’s direct
approval, unless the option for that notification is explicitly turned off.
Competency Assessment
SAVE and CLOSE this workbook. Leave Excel open for the next project.
SAVE and CLOSE this workbook. Leave Excel open for the next project.
Proficiency Assessment
Project 9-
9-3:
3: Hot S
Sauce
auce
ce Sales
Sales Report
Rep
eport
ep
You workrk in
n the
the ac
acco
accounting
coun
counti
un ting department
ti dep
d epartm
ep tmen
tm ent of a n non
nonprofit
onpr
onprofi
pr ofit orga
ofi organization
gani
ga niza
ni zati
zation that manufactures jars of
ti
recipe
pes of homemade
pe
various recipes hom
omem
om emade ho
em hot sauc
uce,
uc e, for resale
sauce, resal
alee by cha
al harity groups.
ha
charity gro
roup
ro ups. In this project, you combine
up
eets wor
three sheets orth of data
or
worth da into
int
ntoo a single
nt sing
ngle
ng le sheet
sshe
heet
he et ttha
hatt ca
ha
that cann be expanded
eexpan
ande
an ded
de d and
an collapsed, and that shows
subtotals for each month.
20. Select the entire worksheet. In the Outline group, click Hide Detail. Both rows
and columns are collapsed to reveal just the sales summaries. Widen column J, if
necessary.
SAVE and CLOSE this workbook. Leave Excel open for the next project.
SAVE the workbook as 09 Charter Employees Solution. Leave the workbook open for the
next project.
Mastery Assessment
SAVE the newly loaded workbook as 09 Charter Employees Solution.xlsm. CLOSE the
2006+ Employees workbook and leave Charter Employees open for the next project.
GET READY. USE the 09 Charter Employees Solution.xlsm workbook from the previous
project.
1. OPEN Sheet2. Change the number formats for cell ranges F2:L36 and N2:P36 to
Accounting. Change the number formats for M2:M36 to Percentage with two decimal
places.
2. OPEN Sheet1 and expand the group. Change the heading for column J to 401K. Add
a new column to the left of 401K named 401K rate. Add three columns to the right of
Employee Name called Title, First name, and Last name. Move Employee ID to column
B. Rename the REGULAR_HO column Hours. Add a column to the right of Hours named
Rate. Delete the Total Deductions column. Leave NET_PAY erroneous for the moment.
3. Copy the contents of Sheet2 to the end of the table in Sheet1 so that their Employee ID
fields align with one another.
4. Relocate the rows with full-name entries in the Employee Name column to the bottom
of the table in Sheet1, so that the relocated cells are automatically given the table
format.
5. Click any cell in the table. On the DATA tab, in the Data Tools group, click Remove
Duplicates.
6. In the Remove Duplicates dialog box,deselect all fields except the unique Employee ID
number. Click OK. Excel reports the number of duplicate employee records that were
removed. Click OK to dismiss the notice.
284 Lesson 9
7. Because all the old employees were apparently duplicated, delete the Employee Name
column.
8. Re-insert the Total deductions column and just before the NET_Pay column, type its
formula, this time being careful to omit 401K rate from the calculation.
9. Enter a new formula for the NET_PAY column starting at the top row and filling down,
subtracting Total deductions from GROSS_PAY.
10. Widen any partly-visible columns if necessary.
11. Apply boldface to the final column of the table.
Circling Back 2
The Graphic Design Institute tracks many different types of data on its students, such as name,
country of origin, the general type of program (accelerated or regular), tuition costs, and the
month in which the student starts his or her program. In addition, instructors must maintain
grade books, which track grades for each student for each course taken. In this set of projects, you
apply formatting to cells and entire worksheets, search and replace text in individual worksheets
and across a workbook, and sort, filter, and subtotal data tables.
GET READY. USE the workbook you saved in the previous project.
1. Double-click the border between the rows 1 and 2 headings to automatically resize row
1 to fit the contents.
286 Circling Back 2
2. Select row 2. On the HOME tab, in the Cells group, click the Format button arrow, select
Row Height, in the Row Height text box, type 18.75, and then click OK.
3. Double-click the border between the columns D and E headings to automatically resize
column D to fit the contents.
4. Click the PAGE LAYOUT tab, and in the Themes group, click the Themes button arrow
to open the gallery. Select the Integral theme.
5. Click cell A1. Click the HOME tab, and in the Font group, change the font size to 24.
6. Change the font size of the content in cell A2 to 14.
7. Select cells A3:E46. Change the font size to 12.
8. Adjust the size of each column as follows:
Column A: 20
Column B: 15
Column C: 12
Column D: 10
Column E: 13
9. Click the VIEW tab, and in the Window group, click the Freeze Panes button arrow, and
then select Unfreeze Panes.
10. Click the INSERT tab, and in the Text group, click the Header & Footer button.
11. Click the HEADER & FOOTER TOOLS DESIGN tab, in the Header & Footer group, click
the Headerer button
ader
ad on arrow,
arrow
ow, and
ow and then
en ssel
select
elect Sh
el Sheet1,
Shee
eet1
ee t1,, Co
t1 Confi
Confidential,
nfide
nfi dential,
de l, Page
P 1.
12. Click anywhere
ywhe
yw here
he re in
in the
the header.
header
he er.. On the
er the HEADER
HEADE
DER & FOOTER
DE FO ER TOOLS
TOO
T OOLS
OO LS DESIGN tab, in the
Navigation
tion group,
gro
g roup, click
ro clic
cl ickk the Go to Fo
ic Footer butto
button.
ton.
to
13. In the Header
eade
derr & Footer
de Foot
oter
ot er group,
gro
roup
ro up,, click
up clic
ickk the
ic the Fo
Footer
Foot er bu
oter
ot button
butt
tton
tt on arrow
ow a
and sselect the file name
option, which is the sixth option in the list.
14. Press Ctrl + H to open the Find and Replace dialog box to the Replace tab. In the Find
What box, type accelerated and press Tab. In the Replace With box, type Accelerated.
Click the Options button and select the Match case checkbox. Click the Replace All
button. After the words are replaced, click OK, and then click Close.
15. On the status bar, click the Normal view button to return to Normal view.
16. SAVE the workbook as Student Roster 2 Solution in the Circling Back folder, and then
CLOSE the file.
xcel
xc el open
LEAVE Excel ope
pen
pe n for
fo the
the ne
next
xt proje
ject
je ct.
ct
project.
Project 4: W
Working
Wor
orking w
or with Data
Dat
ataa
at
The chief financial officer created a new worksheet based on the Contributions worksheet. She
would like you to create two groups—one for organizations and another for individuals. In each
group, she wants you to sort by the type of fund and then the contribution amount (highest to
lowest), and provide subtotals for each fund in both groups.
14. On the DATA tab, in the Outline group, click Subtotal. The Subtotal dialog box appears.
15. In the At Each Change In list box, select Fund.
16. In the Use Function list box, verify that Sum appears.
17. In the Add Subtotal To list box, verify that only Amount is selected.
18. Near the bottom of the dialog box, verify that only Replace Current Subtotals and
Summary Below Data are selected.
19. Click OK. Excel inserts subtotal rows after each type of fund in both groups.
20. Highlight row 45 (the Total Contributions row). Use the Format Painter to copy
formatting from row 45 to row 44.
21. Delete row 45.
22. SAVE the workbook as Contributions Sorted Solution in the Circling Back folder, and
then CLOSE the file.
CLOSE Excel.