Professional Documents
Culture Documents
Excel 2013 - PivotTables and Macros - studentFINAL
Excel 2013 - PivotTables and Macros - studentFINAL
Excel 2013:
PivotTables and
Macros
To w s o n U n i v e r s i t y
O f f i c e o f Te c h n o l o g y S e r v i c e s
OT S Training
Excel 2013:
PivotTables and
Macros
Excel 2013: PivotTables and Macros
Part Number: 222784
Course Edition: 1.0
Acknowledgements
PROJECT TEAM
Notices
DISCLAIMER
While Logical Operations, Inc. takes care to ensure the accuracy and quality of these materials, we cannot guarantee their
accuracy, and all materials are provided without any warranty whatsoever, including, but not limited to, the implied warranties of
merchantability or fitness for a particular purpose. The name used in the data files for this course is that of a fictitious company. Any
resemblance to current or future companies is purely coincidental. We do not believe we have used anyone's name in creating this
course, but if we have, please notify us and we will change the name in the next revision of the course. Logical Operations is an
independent provider of integrated training solutions for individuals, businesses, educational institutions, and government agencies.
Use of screenshots, photographs of another entity's products, or another entity's product name or service in this book is for editorial
purposes only. No such use should be construed to imply sponsorship or endorsement of the book by, nor any affiliation of such
entity with Logical Operations. This courseware may contain links to sites on the internet that are owned and operated by third
parties (the "External Sites"). Logical Operations is not responsible for the availability of, or the content located on or through, any
External Site. Please contact Logical Operations if you have any concerns regarding such links or External Sites.
TRADEMARK NOTICES
Logical Operations and the Logical Operations logo are trademarks of Logical Operations, Inc. and its affiliates.
® ® ®
Microsoft Office Excel 2010 is a registered trademark of Microsoft Corporation in the U.S. and other countries. Microsoft Office
® ® ®
Outlook and Microsoft SharePoint are also registered trademarks of Microsoft Corporation in the U.S. and other countries. The
other Microsoft products and services discussed or described may be trademarks or registered trademarks of Microsoft Corporation.
All other product and service names used may be common law or registered trademarks of their respective proprietors.
Copyright © 2012 Logical Operations, Inc. All rights reserved. Screenshots used for illustrative purposes are the property of the
software proprietor. This publication, or any part thereof, may not be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, storage in an information retrieval system, or otherwise, without
express written permission of Logical Operations, 500 Canal View Boulevard, Rochester, NY 14623, (800) 456-4677. Logical
Operations’ World Wide Web site is located at www.logicaloperations.com.
This book conveys no rights in the software or other products about which it was written; all use or licensing of such software or
other products is the responsibility of the user according to terms and conditions of the owner. Do not make illegal copies of books
or software. If you believe that this book, related materials, or any other Logical Operations materials are being reproduced or
transmitted without permission, please call (800) 456-4677.
Excel 2013: PivotTables
and Macros
Lesson Labs.................................................................................61
Solutions..................................................................................... 63
Glossary...................................................................................... 65
Index...........................................................................................69
1 Analyzing Data with
PivotTables, Slicers, and
PivotCharts
Lesson Time: 1 hour
Lesson Objectives
In this lesson, you will:
• Create a PivotTable.
• Filter data by using slicers.
• Analyze data by using PivotCharts.
Lesson Introduction
Excel has a variety of ways to store and view data. You've already built tables and charts.
Now you're ready to view your data in entirely new ways.
In this lesson, you will analyze data by using PivotTables, slicers, and PivotCharts.
2 | Excel 2013: PivotTables and Macros
TOPIC A
Create a PivotTable
The activities in this Picture yourself standing on the corner of a busy intersection in the downtown area of a major city.
lesson are written in a Cars are zooming by on the roads, large office buildings surround you, people hustle and bustle
continuous fashion. about moving toward their various destinations.
Each new activity after
the first builds upon the You are facing north, looking up the large thoroughfare.
previous activity. Now, imagine you don't move from where you are on the corner, you simply pivot to the left 90
Consider teaching the degrees so that you are now facing west. Same city, same corner, same buildings and people, just a
conceptual content by slightly different perspective. Now you pivot to the left again, another 90 degrees. You're now facing
keying through the south. Again, it's still the same city and people and corner, just a slightly different view. The
activities with the buildings that were behind you when you were facing north are now right in front of you. What was
students and teaching
the material as it comes
originally on your left is now on your right. One more 90 degree turn to the left and you're facing
up in the activities. east. Same story.
The city is your dataset. It is what it is. You are the PivotTable.
Ask students, “What do
you think PivotTables
do?” Direct answers to PivotTables
“change your
perspective on the data.” A PivotTable is a dynamic table that enables you to reposition the columns and rows of a raw dataset
A Standard Table without altering the data. The repositioned columns and rows provide new perspectives on the data.
PivotTables “pivot” columns into rows and rows into columns.
Consider the following two tables. The first table is the raw data table. The second table is a
PivotTable built from the dataset in the first table. Observe how, in the raw data table, Genre and
Market are both column headings.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 3
In the PivotTable, the genres have become the row headings, and each individual Market has
become a column heading.
This particular PivotTable shows you how many units of each genre have sold in each market. All of
that information is in the raw data, but it's a lot easier to find when you let a PivotTable find and
organize it for you.
A PivotTable
The PivotTable does not change the raw data; it changes only your perspective on the data.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
4 | Excel 2013: PivotTables and Macros
You drag fields from the Choose fields to add to report section to where you want them to appear
in the PivotTable. In this example, Genre was dragged into the ROWS area because the genres will
appear as the row headings, and Market was dragged into the COLUMNS area because the
markets will appear as the column headings. Total Units to Date will be dragged to the VALUES
area because Total Units is the value you want to calculate. Excel defaults to SUM; however, there
are several other mathematical and statistical functions you can apply to the VALUES area.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 5
The functions available here work the same way these functions work elsewhere in Excel. For
example, if you select Min, the PivotTable will return the minimum value. In this example, the
author who has sold the least number of total units in APAC is the author who has sold 1417 units.
Ask students, “What do
you notice about the
Grand Totals?” Direct
answers to, “In this MIN
example, the Grand
Totals identify the lowest
value in the column or
row.” Then ask, “What
do you suppose the
Grant Totals would show
if you summarized by
Average?” Direct
answers to, “The
average value of the row
Figure 1-5: Summarizing values by using the MIN function. or column.”
Summarizing Values by
Using the MIN Function
The Show Values As Functionality of a PivotTable
In addition to selecting how you want to summarize the data in a PivotTable, you can also select The Show Values As
how you want to show the values. When set to No Calculation, the values will appear by using Options
only the summary function you select from the Summarize Values By options.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
6 | Excel 2013: PivotTables and Macros
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 7
However, look what happens when you change Summarize Values By to Count but keep Show
Values As at Rank Largest to Smallest. In this case, the PivotTable is answering the question,
“How do the markets rank by total number of titles sold in each genre?” APAC is now ranked
second by this criterion.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
8 | Excel 2013: PivotTables and Macros
Function Description
External Data
In a perfect world, all of your data would live in external data sources. For example, you might have
an HR database, a sales database, an inventory database, and a call center database. Depending on
the size of your business, this might even be a requirement.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 9
Rather than export data from those sources and store it in Excel, a more efficient method is to
connect Excel directly to those external sources. If you store data in Excel and in the external data
sources, you run the serious risk of the data in Excel not being up-to-date.
The biggest benefit of connecting to external data sources is the accuracy of the data: your data will
always be up-to-date. Which is precisely what you want for making business decisions.
PowerPivot is one of the tools that makes it very easy for you to connect to external data sources.
However, Excel has many other built-in tools to make the connections to and management of
external connections easy.
For more information on how to connect to and manage external data, search for external data in
the Excel 2013 Help system.
Create a PivotTable
To create a PivotTable:
1. Identify a few key questions you'd like the PivotTable to be able to answer about your data.
2. On scratch paper, sketch out the structure you'd like the PivotTable to take. Which fields from
the source data will be the rows? Which fields will be the columns? On which field do you want
to run the calculations?
3. In Excel 2013, select INSERT→Tables→PivotTable.
4. In the Create PivotTable dialog box, select the data you want to analyze.
• If the data is in the current workbook, select the Select a table or range radio button, and
then select the Collapse Dialog button and select the table or range.
• If the data is in an external source, select the Use an external data source radio button, and
then select the data source.
5. In the Create PivotTable dialog box, choose whether you want to add the PivotTable to a New
Worksheet or to an Existing Worksheet.
6. Select OK.
7. In the PivotTable Fields panel, using the structure you sketched out on scratch paper as a
guide, from the Choose fields to add to report list, drag the fields that will be rows to the
ROWS area, the fields that will be columns to the COLUMNS area, and the fields on which
you want to run calculations to the VALUES area.
8. If necessary, drag fields to the FILTERS field. Note: FILTERS in a PivotTable work in the
same way as the Sort functionality on a standard table, enabling you to refine the PivotTable by
which ever criteria appears in the FILTERS field.
9. On the worksheet, test your PivotTable.
10. As necessary, on the PivotTable, change the Summarize Values By and Show Values As
settings.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
10 | Excel 2013: PivotTables and Macros
ACTIVITY 1-1
Creating PivotTables
Data Files
C:\091015Data\Analyzing Data with PivotTables, Slicers, and PivotCharts\Author_Data_05.xlsx
Scenario
Your data analysis and visualization needs continue to grow.
Two primary questions that continue to come up are:
• What's the total number of units sold per genre in each market we serve?
• For each author and book, what are the total sales of electronic books versus the total sales of
print books?
To answer these questions, you've decided to create two pivot tables, one that addresses the genres-
by-market question and one that addresses the sales of electronic versus print for authors and book
titles question.
2. Add a PivotTable that answers the primary question, “What's the total number of units sold per genre in
each market we serve?”
a) On the Sales Dashboard spreadsheet, select cell AP1.
b) Type pvtblGenresAndMarkets
c) Select cell AP2.
d) Select INSERT→Tables→PivotTable.
e) In the Table/Range field, type tblSalesData
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 11
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
12 | Excel 2013: PivotTables and Macros
h) Drag Market from the Choose fields to add to report list to the COLUMNS area.
i) Drag Total Units to Date from the Choose fields to add to report list to the VALUES area.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 13
j) Select any cell in the PivotTable and then, on the PIVOTTABLE TOOLS ANALYZE tab, in the
PivotTable group, clear the contents of the PivotTable Name field and type pvtblGenresAndMarkets
k) Press Enter.
Point out to students that
3. Use the PivotTable to answer the question, “Which genre is our biggest overall seller?” even a small PivotTable
a) Right-click cell AU4 and select Sort→Sort Largest to Smallest. can answer a huge array
of related granular
4. Which genre is the biggest overall seller? questions.
5. Use the PivotTable to answer the question, “For APAC and EMEA only, what is the combined number
of total units sold for Romance and Fantasy?”
a) From the Column Labels drop-down list, uncheck the Select All check box, check APAC and EMEA,
and then select OK.
b) From the Row Labels drop-down list, uncheck the Select All check box, check Fantasy and
Romance, and then select OK.
6. What is the combined number of total units sold for Romance and Fantasy in APAC and EMEA?
A: The total units sold for Fantasy and Romance in APAC and EMEA is 63730961.
7. Use the PivotTable to answer the question, “What percentage of total unit sales is made up of LA’s
Fantasy genre sales?”
a) Clear all filters from the rows and column label lists.
b) Right-click any of the data cells.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
14 | Excel 2013: PivotTables and Macros
9. Use the PivotTable to answer the question, “Which market has the highest percentage of SF sales?”
a) Right-click any of the data cells.
b) Select Show Values As→% of Row Total.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 15
14. Use the PivotTable to answer the question, “For author 1011, which book has the highest sales?”
a) Right-click cell AS13 and select Sort→Sort Largest to Smallest.
15. For author 1011, which book has the highest sales?
A: For author 1011 BookTitle0052 has the highest sales at $276,914.82.
Ask students, “What did
16. Use the PivotTable to answer the question, “What percentage of author 1048’s total sales are electronic you notice about those
books?” last two sorts?” Direct
a) Select the Row Labels drop-down list. answers to: “If you have
b) In the Search box, type 1048 grouped rows and you
place the cursor in a
c) Press Enter.
parent row (for example,
d) Right-click cell AQ12, and then select Show Values As→% of Row Total. an author row in this
PivotTable), then the
17. What percentage of author 1048’s total sales are electronic books? entire dataset will sort
A: Electronic book sales account for 16.41% of author 1048’s total sales. based on the parent
rows. If you click in a
18. Save your work as My_Author_Data_05.xlsx child row of one of the
groups (for example, the
book titles) and then
sort, you'll sort within
each group.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
16 | Excel 2013: PivotTables and Macros
TOPIC B
Filter Data by Using Slicers
Once you've created a PivotTable, you will want to make sorting and filtering the data in the table as
efficient as possible. Although you can use the functionality built directly into the PivotTable to find
the answers to your questions, there is another type of functionality that makes sorting and filtering
PivotTables easier: slicers.
Slicers
Slicers and a PivotTable Slicers are filtering tools that filter PivotTable and PivotChart data based on user selections. Slicer
filtering functions in the exact same way as the filtering you're used to seeing on tables, but instead
of selecting filters from a list at the top of table columns, you select filter criteria by selecting
buttons in the slicers. Use the standard Ctrl+click procedure to select more than one non-
contiguous button and Shift+click to select more than one contiguous button.
One slicer can connect to multiple PivotTables and one PivotTable can connect to multiple slicers.
In this example, five slicers have been associated with the PivotTable. The slicers are based on the
fields in the source data.
This example answers questions such as, for all authors selling electronically formatted SF and
Thriller novels in APAC and NA only, what percentage of total unit sales is the Thriller genre in
NA? (The result is 11.67%.) What percentage of total unit sales is the SF genre in APAC? (The
result is 22.67%.) And, what percentage of total unit sales is the Thriller genre overall? (The result is
50.13%.)
Note that you can select slicers from the source data that don't appear as rows or columns in the
PivotTable. Because the slicers and PivotTable come from the same data source, the slicers will filter
the PivotTable accordingly. In the example, Format, Author, and Title are not rows or columns in
the PivotTable. However, when you include the slicers for those fields and select the criteria, the
PivotTable adds those criteria to its filter.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 17
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
18 | Excel 2013: PivotTables and Macros
ACTIVITY 1-2
Adding Slicers
Scenario
To make it easier to filter data in your PivotTables, you've decided to incorporate slicers into the
Sales Dashboard worksheet.
Rather than add separate sets of slicers to each PivotTable, you plan to add one set of slicers and
then connect the slicers to the appropriate PivotTables.
1. In My_Author_Data_05.xlsx, add slicers that will enable you to sort and filter the
pvtblGenresAndMarkets PivotTable by author, title, genre, market, and format.
a) Select any cell in the pvtblGenresAndMarkets PivotTable, and then select PIVOTTABLE TOOLS
ANALYZE→Filter→Insert Slicer.
b) In the Insert Slicers dialog box, check Author, Title, Genre, Format, and Market, and then select OK.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 19
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
20 | Excel 2013: PivotTables and Macros
c) Select OK.
Check in with students d) Select any cell in pvtblAuthorsAndFormats, and then, on the PIVOTTABLE TOOLS ANALYZE tab,
to assess their progress in the Filter select Filter Connections.
up to this point. e) In the Filter Connections dialog box, check the box for every slicer.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 21
f) Select OK.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
22 | Excel 2013: PivotTables and Macros
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 23
TOPIC C
Analyze Data by Using PivotCharts
You've created tables and PivotTables, and you're familiar with the difference between the two.
You've also created charts. Now, you'd like to leverage the flexibility of PivotTable filtering in your
charts. That's where PivotCharts come in.
PivotCharts
PivotCharts are interactive charts that allow you to filter data on the fly by selecting filter data either Slicers and a PivotChart
directly on the chart or via slicers that have been connected to the chart.
The PivotChart in this example answers the question, “Regardless of format, which Fantasy title of
Author 1005 is selling the best in LA?” The answer is BookTitle0003 with just over 8,000 units sold.
Similar to a PivotTable, once you connect slicers to a PivotChart, you can filter the data by using
either the slicers or the lists directly on the chart. Whichever you use, the other will reflect the filter.
For example, if you select LA in the slicer, only LA will be selected in the Genre list on the chart.
Insert a PivotChart
To insert a PivotChart:
1. Select any cell in the desired PivotTable. Note: You can also create a PivotChart using a data
range.
2. Select PIVOTTABLE TOOLS ANALYZE→Tools→PivotChart.
3. In the Insert Chart dialog box, select the type of chart you want to insert.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
24 | Excel 2013: PivotTables and Macros
4. Select OK.
5. Position the chart on the worksheet and format as needed.
6. Filter the chart as needed.
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 25
ACTIVITY 1-3
Creating a PivotChart
Scenario
To further enhance the workbook, you've decided to add a PivotChart to the Sales Dashboard. This
PivotChart will be controlled by the same slicers that currently control the two PivotTables that
already exist on the Sales Dashboard.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
26 | Excel 2013: PivotTables and Macros
Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts OTS Training
Excel 2013: PivotTables and Macros | 27
Summary
In this lesson, you created PivotTables and PivotCharts and discovered the power they give you
when you want to view your data in new and, perhaps, unexpected ways.
You also learned about slicers. Slicers make it easy to select the data you want to filter and view in
your PivotTables and PivotCharts.
PivotTables, PivotCharts, and slicers make data visualization interactive. When data is interactive,
data users begin to engage the data more deeply, uncovering new questions and answers that might
not be readily apparent if the data were presented in a static format.
Consider the types of data your firm generates. What kinds of questions would you like to ask the data?
A: Answers will vary, but consider the various types of data your firm generates in the context of how
PivotTables, PivotCharts, and/or slicers could help you answer questions about your business. These
tools enable you to ask virtually anything of your data, but you will want to make sure that you are
asking questions from a business perspective and not strictly a data analysis perspective.
How could you leverage PivotTables, PivotCharts, and slicers to create interactive dashboards that will help
you uncover new knowledge about your business?
A: Answers will vary, but remember that Excel tools help you quickly find both granular data and trends in
data.
Note: Check your LogicalCHOICE Course screen for opportunities to interact with your
classmates, peers, and the larger LogicalCHOICE online community about the topics covered in
this course or other topics you are interested in. From the Course screen, you can also access
available resources for a more continuous learning experience.
Encourage students to
use the social
networking tools
provided on the
LogicalCHOICE Home
screen to follow up with
their peers after the
course is completed for
further discussion and
resources to support
continued learning.
Towson University Lesson 1: Analyzing Data with PivotTables, Slicers, and PivotCharts
2 Automating Worksheet
Functionality
Lesson Time: 1 hour, 15 minutes
Lesson Objectives
In this lesson, you will:
• Update workbook properties.
• Create and edit a macro.
• Use conditional formatting.
• Add data validation criteria.
Lesson Introduction
From your prior training, you already know the basic functionality of Microsoft® Excel®. As
your projects and worksheets become more complex, you will want ways of streamlining
your projects. Excel offers a number of tools that let you automate your work process. Your
ability to automate will let you work more efficiently and accurately.
30 | Excel 2013: PivotTables and Macros
TOPIC A
Update Workbook Properties
In Excel 2013, you can use the Document panel to add or change the properties of a workbook.
You can enter information that relates to a workbook such as the author, title, keywords, status, and
comments. This information is sometimes referred to as metadata. Other than being added to a
workbook, metadata can also be altered and deleted. The metadata you enter will help you better
manage and locate your workbook files. In this topic, you will update a workbook's properties.
Imagine that your boss needs some sales data from a worksheet for a presentation that she has to
give in a couple of hours. The problem is that with all the workbooks that you use on a daily basis,
you cannot find the right one. Obviously, telling her that you cannot find the numbers or making
something up is not an option. You wish there was some way to help you find the right information.
It can be extremely frustrating to search for something you need, especially when working under a
deadline. In this topic, you will learn how to update workbook properties to help you find and
identify files.
Workbook Properties
Workbook Properties The Workbook Name Properties dialog box has five tabs for specifying properties.
Tab Description
General The General tab shows the file name, type, location, size, MS-DOS
name, creation date, modification date, and access date. It also displays if
the file is read-only. These settings cannot be changed from the
Workbook Name Properties dialog box. This information is supplied by
the system.
Summary Allows you specify the file's title, subject, author, manager, company,
category, keywords, and hyperlink base.
Statistics Shows system information like creation date, last modified date, last
accessed date, and last printed date. It also shows the name of the
person who last saved the file, the revision number (when applicable),
and the total editing time. Data cannot be edited here.
Contents Shows the number of the worksheets by name. Data cannot be edited
here.
Custom Allows you to attach specific information to the file such as destination,
editor, language, and other traits. It is possible to add a property name of
your properties.
ACTIVITY 2-1
Updating Workbook Properties
Data Files
C:\091016Data\Automating Worksheet Functionality\Asian_Royalties.xlsx
Scenario
You work for Fuller & Ackerman Publishing and are managing a project to simplify the payment of
royalties to international authors. Last year there were a number of costly mistakes that took a long
time to resolve because out-of-date and incorrect workbooks were used to calculate payments. To
make sure that this never happens again, your boss wants you to go through all workbooks and
update their properties to make them easier to find and identify.
1. Navigate to the C:\091016Data\Automating Worksheet Functionality folder and open the Excel
worksheet Asian_Royalties.xlsx.
5. Select OK.
ACTIVITY 2-2
Modifying the Default Settings in Excel
Scenario
Your manager likes the changes that you made to file properties to make them easier to find. She
would like to build additional ways of identifying files so the problems that happened last year never
happen again. She suggests that all new files this year have a new font type and size, so that going
forward everyone will be able to easily tell when the files were created.
You may want to show 3. Verify that the default setting for new documents is Arial 12 point.
LearnTO Protect a a) Open a blank workbook.
Worksheet in a b) Type something into a cell and verify that the default type is Arial 12 point.
Workbook from the
c) Close the file without saving.
LogicalCHOICE Course
screen, or have students Note: Check out the LearnTO Protect a Worksheet in a Workbook presentation
navigate out to the from the LearnTO tile for this course on your LogicalCHOICE Course screen.
Course screen and
watch it themselves as a
supplement to your
instruction. If not, please
remind students to visit
the LearnTOs for this
course on their
LogicalCHOICE Course
screen after class for
supplemental
information and
additional resources.
TOPIC B
Create and Edit a Macro
Doing the same thing over and over can get tedious and contribute to data errors and omissions.
However, your organization likely needs to run the same kind of analysis and have a common look
for many different files. Automating frequently used tasks lets you complete your work more
accurately and efficiently. In this topic, you will create and edit a macro. Macros automate complex
tasks to ensure repetitive precision.
Macros
A macro is an automated tool that repeats a set of commands to complete a series of frequently Macros Icon
needed tasks. Every macro must have a unique name. A macro-enabled workbook is saved with
the .xlsm extension. You can create a macro recorder to record the sequence of steps that you want
included in your macro, and then set a command to run the macro. The macro recorder converts
your macro into Visual Basic programming code that can be edited as required. Macros can be saved
in any workbook.
Excel can reference macros in two different ways. Absolute referencing means that you set specific
cells for the macro to work and the macro always uses those cells. Relative referencing means that
cells are specified based on their relationship with other cells (for example, four cells down).
Absolute referencing is the default.
Naming Macros
Naming Macros There are a few rules for naming macros.
• The name must start with a letter.
• The name cannot contain spaces.
• The name can contain letters, numbers, and the underscore character (_).
• The name should not conflict with any other object in the worksheet or workbook, or with any
built-in names.
If these naming rules are not followed, you will get an error message.
Macro Storage
You can save macros in three different sites: the current workbook, a new workbook, or a Personal
Macro workbook. Saving in the current workbook requires that the workbook be open in order to
use it in other files. To save it in any other file, at any time, save as a Personal Macro workbook.
Note: Check out the LearnTO Use Relative Referencing When Recording a Macro
presentation from the LearnTO tile for this course on your LogicalCHOICE Course screen.
Note: If you know how to program in VBA, you can directly write macros using VBA.
Component Description
Project Explorer Displays a hierarchical list of all VBA modules in all open documents. The
normal template is called Normal. Active documents appear as Project objects.
Active templates appear as Template Project objects.
Properties Displays the properties of the object selected in the Project Explorer window.
window A property is a characteristic of the object. One property of a VBA module is
the module's name.
Code Shows the actual VBA code for the macro, which can be edited.
Immediate Shows debugging information from the code or commands typed directly into
window the window.
Macro Settings
The security level applied to a macro can be set in the Macro Settings category of the Trust
Center dialog box. There are five security settings.
Option Description
Disable all macros without Disables all macros in a workbook without issuing a security alert.
notification Only macros saved in the document or from a trusted location
are allowed to run.
Disable all macros with Disables all macros, but it issues a security alert. This is the
notification default setting.
Disable all macros except Disables all macros that are not digitally signed by a trusted
digitally signed macros publisher.
Enable all macros Enables all macros. This is the lowest level of protection, which
could leave your computer open to malicious code.
Trust access to the VBA Allows macros to access the core level of the Microsoft Visual
project object model Basic project model. This option is a security risk for most users,
and it should only be used by developers.
Edit a Macro
To edit a macro:
1. Open the worksheet that has the macro you need to edit.
2. If the security setting is set to disable the macro, you need to enable the macro.
• In the SECURITY WARNING panel, select Enable Content.
3. Select VIEW→Macros→Macros down-arrow→View Macros.
4. In the Macro dialog box, in the Macro name list box, select the macro you need to edit. Then,
select Edit.
5. Make the needed changes in the macro in the code window, and then save your changes.
6. Return to Excel.
7. Test the macro you just edited.
8. Save the file.
Copy a Macro
To copy a macro to another workbook:
1. Open the workbooks you want macros copied from and to.
2. In either open workbook, select VIEW→Macros→Macros down-arrow→View Macros.
3. From the Macro dialog box, select the macro you would like to copy, and then select Edit.
4. From the Microsoft Visual Basic for Applications window, drag the macro you would like to
copy to the desired workbook.
a. In the Project - VBA Project pane, if necessary, expand the hierarchy for the workbook that
contains the macro.
b. In the Modules node, drag the desired macro to the destination workbook.
c. Expand the Modules node in the destination workbook's hierarchy, and then verify that the
macro copied to the workbook.
5. Close the Microsoft Visual Basic for Applications window.
6. Close the workbook that originally contained the macro.
7. Save the destination workbook in the .xlsm file format.
8. If desired, run the macro on the destination workbook.
9. Save and close the file.
ACTIVITY 2-3
Creating a Macro
Data Files
C:\091016Data\Automating Worksheet Functionality\My_Asian_Royalties.xlsx
Scenario
Your sales manager wants you to make all the worksheets from the Asian division look exactly the
same so that they can be more easily identified.
She wants you to make the following changes:
• All the worksheets' titles to red, 24 point.
• All the worksheets' fonts to Times New Roman.
• All column headers to bold.
• All columns of numerical data to the currency format.
Instead of manually making all these changes, you decide to format one worksheet and create a
macro that you will apply to the other two worksheets.
3. Name the macro so that you can reference it for later use.
a) In the Record Macro dialog box, in the Macro name text box, type RoyaltyFormattingMacro
b) In the Shortcut key text box, type R
Note: Excel automatically adds the Shift key to the shortcut in the Record
Macro dialog box because you pressed it when typing the capital "R."
c) In the Store macro in drop-down list, verify that This Workbook is selected.
d) In the Description text box, type This macro sets the formatting for author royalty worksheets.
e) Select OK.
c) In the right pane, under Computer, select the Automating Worksheet Functionality folder displaying
in the Current Folder section.
Note: This saves the file to the folder location from which you opened the
original file.
d) Save the file with the following information:
• File name: My_Asian_Royalties
• Save as type: Excel Macro-Enabled Workbook (*.xlsm)
ACTIVITY 2-4
Editing a Macro
Scenario
Your manager likes the macro, but she wants the title of the worksheets to be a little bit larger, so
she wants you to change it from 24 to 26 point font.
Note: You may need to select text in the cells, and then select the HOME tab
to verify that the font size has changed to 26 in the Font command group.
TOPIC C
Apply Conditional Formatting
Sometimes you need locate some specific data or make some parts of your worksheet stand out. In
this topic, you will apply conditional formatting.
Conditional formatting allows you to set criteria that, if met, will display that information in a
different format so that it is more distinctive. Conditional formatting lets you differentiate between
data more easily.
Conditional Formatting
Conditional Formatting Conditional formatting sets a specific format for cells or a range of cells based on criteria that you set.
Cells can contain numerical or textual data. There are default formats, but you can also set your own
formatting style.
Conditional Formats
There are different conditional formats available from the Conditional Formatting command in
the Styles group on the HOME tab.
Format Purpose
Highlight Cells Rules Finds cells within a range. You format these cells based on a
comparison operator. You apply this format by selecting the
necessary option from the Highlight Cells submenu.
Top/Bottom Rules Finds the highest and lowest values in a range and allows you to
set cutoff values. You apply this format by selecting the necessary
option from the Top/Bottom Rules submenu.
Data Bars Shows the value of a cell relative to other cells. The value in the
cell sets the length of the data bar. You can set this format by
selecting the data bar format from the Data Bars gallery. It is
possible to customize a data bar.
Format Purpose
Color Scales Shows data distribution and variation. The shade of color used
represents higher, middle, or lower values. You set this format by
picking a color scheme from the Color Scales gallery. It is
possible to customize a color scale.
Icon Sets Allows you to annotate and classify data into three to five
categories using icon sets. Every category is represented by an
icon. You apply this format by selecting an icon set type from the
Icon Sets gallery. It is possible to customize icon sets.
Format all cells based on their Cells are formatted depending on their values. There is no
values need to set maximum or minimum values. This option cannot
be used for text; it can only be used for numeric data.
Format only cells that contain Cell format is set by its numeric, text, or data type.
Format only top or bottom Selects the top or bottom percentage of cells in the range.
ranked values
Format only values that are Cells are formatted if they are above or below the average.
above or below average
Clear Rules
You can remove conditional formatting rules from the Clear Rules submenu in the Conditional
Formatting drop-down list. From this menu, you can delete conditional formatting rules from a
worksheet, selected cells, tables, or PivotTables.
Note: Check out the LearnTO Use Data Bars and Icon Sets presentation from the LearnTO
tile for this course on your LogicalCHOICE Course screen.
ACTIVITY 2-5
Applying Conditional Formatting
Scenario
The Asian sales manager would like to know if there is an easy way to highlight all authors who earn
more than $25,000 because there maybe additional tax requirements for authors who earn this
much. You will set conditional formatting to apply to all authors who make this amount.
1. Set conditional formatting so that authors who earn more than $25,000 are highlighted.
a) Select the Author Sales worksheet.
b) Select cells D5 to D15.
c) Select HOME→Styles→Conditional Formatting.
d) From the Conditional Formatting drop-down list, select Highlight Cells Rules, and then select
Greater Than.
e) In the Format cells that are GREATER THAN field, type 25000
f) Select OK.
2. Verify that the authors who have earned more than $25,000 now have their royalties highlighted with
dark red text on a light red cell background.
ACTIVITY 2-6
Editing a Conditional Formatting Rule
Scenario
The manager likes the new formatting, which makes it very easy for his people to see exactly who is
making more than the threshold of $25,000. However, he apologizes because he gave you the wrong
information. Actually, authors who make more than $35,000 may face additional tax liability. He
would also like you change the formatting because he thinks the color scheme might be confusing.
3. Verify that the conditional formatting now applies only to values above $35,000, and that the text is now
blue.
TOPIC D
Add Data Validation Criteria
Restricting the type of data that can be input into your workbook gives you greater control over the
information you need to work with. Some cells really need a numeral, others should have times,
dates, or whole numbers. In this topic, you will add data validation criteria.
Setting data validation rules before you enter data guarantees that all input values will fall within a
range that you set.
Data Validation
Data Validation Data validation restricts the input type of a value based on a specific set of criteria. When you apply
data validation to a cell or a range of cells, the cells can only accept the specified type of data. Trying
to enter data that does not meet the criteria set for the cells will generate an error message. You can
set a specific input message to inform users why the data they attempted to enter is unacceptable.
Tab Function
Settings Sets the permitted the value type, such as decimal, date, and time. The possible
range can be set here. You can also create a drop-down list that only allows
particular entries here.
Input Message Sets the specific title for and the description of the data allowed in the cell.
Error Alert Allows you to set the style, title, and description of an error that displays when
the input data is not within the specified criteria.
5. In the text boxes below the Data drop-down list, set any needed values for a range. Note:
Different text boxes display depending on the comparison operator you select in the Data drop-
down list.
6. On the Input Message tab, create a custom message.
a. In the Title text box, type a title.
b. In the Input Message text area, if desired, type an optional message.
7. To create an error message, make changes to the default settings on the Error Alert tab.
a. From the Style drop-down list, select an error icon.
b. In the Title text box, enter a title.
c. In the Error message text box, type the error message.
8. Select OK to apply the data validation criteria.
9. Test your rules by trying to input invalid data into the range you just applied validation to. Note:
Text and data already entered in the cells that does not meet the data validation criteria will not
be affected. If you try to change the entries after the data validation has been applied, it must
meet the set criteria.
ACTIVITY 2-7
Adding Data Validation Criteria
Scenario
The manager of the Asian sales division would like to add a place in the royalties workbook where
her staff can add and track their sales. There have been some problems in the past with data being
entered in the wrong place, which required a long and miserable effort to correct. You will need to
apply data validation criteria to avoid this issue in the future.
1. Set the Sales column so that only whole numbers can be input.
a) If necessary, navigate to the Author Sales worksheet.
b) Select cells C5:C15.
c) Select DATA→Data Tools→Data Validation→Data Validation.
d) In the Data Validation dialog box, on the Settings tab, from the Allow drop-down list, select Whole
number.
e) In the Data drop-down list, verify that between is selected.
f) In the Minimum text box, type 0
g) In the Maximum text box, type 1000000
2. Set an error message for the Sales column so that your message displays when someone tries to enter
data that is not a whole number.
a) Select the Error Alert tab.
b) In the Style drop-down list, select Warning.
c) In the Title text box, type Sales Column Data Error
d) In the Error message text box, type This column requires a whole number.
e) Select OK.
Summary
In this lesson, you automated worksheet functionality. You created and edited macros to complete
commonly occurring tasks. You applied conditional formatting to give yourself additional flexibility
over the data in your worksheet. Finally, you set data validation criteria that restricted the type of
data that could be entered in a cell or range of cells.
Which of these automation tools do you think will be most important or useful to you? Why?
A: Answers will vary, but different people in different businesses may value any of these time-saving
options. For most people, macros can be the most useful because they enable someone to quickly
establish a style that can easily be applied to many other worksheets. For some people, conditional
formatting will be very helpful in making workbooks more efficient.
How does using workbooks make business easier? Will these automation tools make the process of
building and maintaining workbooks easier for you?
A: Answers will vary, but may include that many complicated calculations that businesses require had to
be done by hand or with a calculator in the past. Having this work done automatically improves the
accuracy of information and lets a business run more sophisticated formulas and data analysis than
would otherwise be possible.
Note: Check your LogicalCHOICE Course screen for opportunities to interact with your
classmates, peers, and the larger LogicalCHOICE online community about the topics covered in
this course or other topics you are interested in. From the Course screen, you can also access
available resources for a more continuous learning experience.
Encourage students to
use the social
networking tools
provided on the
LogicalCHOICE Home
screen to follow up with
their peers after the
course is completed for
further discussion and
resources to support
continued learning.
Lesson labs are provided as an additional learning resource for this course. The labs may or
may not be performed as part of the classroom activities. Your instructor will consider setup
issues, classroom timing issues, and instructional needs to determine which labs are
appropriate for you to perform, and at what point during the class. If you do not perform
the labs in class, your instructor can tell you if you can perform them independently as self-
study, and if there are any special setup requirements.
62 | Excel 2013: PivotTables and Macros
Data Files
C:\091016Data\Automating Worksheet Functionality\Promotions_Budget.xlsx
Scenario
The promotions workbook has two worksheets. Your manager wants them to look
exactly the same so that the department's documents are consistent. She would like you
to:
• Highlight any total higher than $3,000 by applying a yellow fill with dark yellow
text.
• Cap the maximum value at $5,000 using data validation.
• Increase the font size for the monthly total to 16 point.
It will be easier to make all the changes to one worksheet and record the process so
that you can apply it to any other worksheets.
3. Select cells C5:C10. Use conditional formatting to highlight any value greater than $3000.
4. Set data validation criteria so that the maximum value for column C is $5000.
5. Select cells B13 and C13 and change the font size to 16 point.
7. Run the macro on the other worksheet, and then save and close the file.