
- •About the Author
- •About the Technical Editor
- •Credits
- •Is This Book for You?
- •Software Versions
- •Conventions This Book Uses
- •What the Icons Mean
- •How This Book Is Organized
- •How to Use This Book
- •What’s on the Companion CD
- •What Is Excel Good For?
- •What’s New in Excel 2010?
- •Moving around a Worksheet
- •Introducing the Ribbon
- •Using Shortcut Menus
- •Customizing Your Quick Access Toolbar
- •Working with Dialog Boxes
- •Using the Task Pane
- •Creating Your First Excel Worksheet
- •Entering Text and Values into Your Worksheets
- •Entering Dates and Times into Your Worksheets
- •Modifying Cell Contents
- •Applying Number Formatting
- •Controlling the Worksheet View
- •Working with Rows and Columns
- •Understanding Cells and Ranges
- •Copying or Moving Ranges
- •Using Names to Work with Ranges
- •Adding Comments to Cells
- •What Is a Table?
- •Creating a Table
- •Changing the Look of a Table
- •Working with Tables
- •Getting to Know the Formatting Tools
- •Changing Text Alignment
- •Using Colors and Shading
- •Adding Borders and Lines
- •Adding a Background Image to a Worksheet
- •Using Named Styles for Easier Formatting
- •Understanding Document Themes
- •Creating a New Workbook
- •Opening an Existing Workbook
- •Saving a Workbook
- •Using AutoRecover
- •Specifying a Password
- •Organizing Your Files
- •Other Workbook Info Options
- •Closing Workbooks
- •Safeguarding Your Work
- •Excel File Compatibility
- •Exploring Excel Templates
- •Understanding Custom Excel Templates
- •Printing with One Click
- •Changing Your Page View
- •Adjusting Common Page Setup Settings
- •Adding a Header or Footer to Your Reports
- •Copying Page Setup Settings across Sheets
- •Preventing Certain Cells from Being Printed
- •Preventing Objects from Being Printed
- •Creating Custom Views of Your Worksheet
- •Understanding Formula Basics
- •Entering Formulas into Your Worksheets
- •Editing Formulas
- •Using Cell References in Formulas
- •Using Formulas in Tables
- •Correcting Common Formula Errors
- •Using Advanced Naming Techniques
- •Tips for Working with Formulas
- •A Few Words about Text
- •Text Functions
- •Advanced Text Formulas
- •Date-Related Worksheet Functions
- •Time-Related Functions
- •Basic Counting Formulas
- •Advanced Counting Formulas
- •Summing Formulas
- •Conditional Sums Using a Single Criterion
- •Conditional Sums Using Multiple Criteria
- •Introducing Lookup Formulas
- •Functions Relevant to Lookups
- •Basic Lookup Formulas
- •Specialized Lookup Formulas
- •The Time Value of Money
- •Loan Calculations
- •Investment Calculations
- •Depreciation Calculations
- •Understanding Array Formulas
- •Understanding the Dimensions of an Array
- •Naming Array Constants
- •Working with Array Formulas
- •Using Multicell Array Formulas
- •Using Single-Cell Array Formulas
- •Working with Multicell Array Formulas
- •What Is a Chart?
- •Understanding How Excel Handles Charts
- •Creating a Chart
- •Working with Charts
- •Understanding Chart Types
- •Learning More
- •Selecting Chart Elements
- •User Interface Choices for Modifying Chart Elements
- •Modifying the Chart Area
- •Modifying the Plot Area
- •Working with Chart Titles
- •Working with a Legend
- •Working with Gridlines
- •Modifying the Axes
- •Working with Data Series
- •Creating Chart Templates
- •Learning Some Chart-Making Tricks
- •About Conditional Formatting
- •Specifying Conditional Formatting
- •Conditional Formats That Use Graphics
- •Creating Formula-Based Rules
- •Working with Conditional Formats
- •Sparkline Types
- •Creating Sparklines
- •Customizing Sparklines
- •Specifying a Date Axis
- •Auto-Updating Sparklines
- •Displaying a Sparkline for a Dynamic Range
- •Using Shapes
- •Using SmartArt
- •Using WordArt
- •Working with Other Graphic Types
- •Using the Equation Editor
- •Customizing the Ribbon
- •About Number Formatting
- •Creating a Custom Number Format
- •Custom Number Format Examples
- •About Data Validation
- •Specifying Validation Criteria
- •Types of Validation Criteria You Can Apply
- •Creating a Drop-Down List
- •Using Formulas for Data Validation Rules
- •Understanding Cell References
- •Data Validation Formula Examples
- •Introducing Worksheet Outlines
- •Creating an Outline
- •Working with Outlines
- •Linking Workbooks
- •Creating External Reference Formulas
- •Working with External Reference Formulas
- •Consolidating Worksheets
- •Understanding the Different Web Formats
- •Opening an HTML File
- •Working with Hyperlinks
- •Using Web Queries
- •Other Internet-Related Features
- •Copying and Pasting
- •Copying from Excel to Word
- •Embedding Objects in a Worksheet
- •Using Excel on a Network
- •Understanding File Reservations
- •Sharing Workbooks
- •Tracking Workbook Changes
- •Types of Protection
- •Protecting a Worksheet
- •Protecting a Workbook
- •VB Project Protection
- •Related Topics
- •Using Excel Auditing Tools
- •Searching and Replacing
- •Spell Checking Your Worksheets
- •Using AutoCorrect
- •Understanding External Database Files
- •Importing Access Tables
- •Retrieving Data with Query: An Example
- •Working with Data Returned by Query
- •Using Query without the Wizard
- •Learning More about Query
- •About Pivot Tables
- •Creating a Pivot Table
- •More Pivot Table Examples
- •Learning More
- •Working with Non-Numeric Data
- •Grouping Pivot Table Items
- •Creating a Frequency Distribution
- •Filtering Pivot Tables with Slicers
- •Referencing Cells within a Pivot Table
- •Creating Pivot Charts
- •Another Pivot Table Example
- •Producing a Report with a Pivot Table
- •A What-If Example
- •Types of What-If Analyses
- •Manual What-If Analysis
- •Creating Data Tables
- •Using Scenario Manager
- •What-If Analysis, in Reverse
- •Single-Cell Goal Seeking
- •Introducing Solver
- •Solver Examples
- •Installing the Analysis ToolPak Add-in
- •Using the Analysis Tools
- •Introducing the Analysis ToolPak Tools
- •Introducing VBA Macros
- •Displaying the Developer Tab
- •About Macro Security
- •Saving Workbooks That Contain Macros
- •Two Types of VBA Macros
- •Creating VBA Macros
- •Learning More
- •Overview of VBA Functions
- •An Introductory Example
- •About Function Procedures
- •Executing Function Procedures
- •Function Procedure Arguments
- •Debugging Custom Functions
- •Inserting Custom Functions
- •Learning More
- •Why Create UserForms?
- •UserForm Alternatives
- •Creating UserForms: An Overview
- •A UserForm Example
- •Another UserForm Example
- •More on Creating UserForms
- •Learning More
- •Why Use Controls on a Worksheet?
- •Using Controls
- •Reviewing the Available ActiveX Controls
- •Understanding Events
- •Entering Event-Handler VBA Code
- •Using Workbook-Level Events
- •Working with Worksheet Events
- •Using Non-Object Events
- •Working with Ranges
- •Working with Workbooks
- •Working with Charts
- •VBA Speed Tips
- •What Is an Add-In?
- •Working with Add-Ins
- •Why Create Add-Ins?
- •Creating Add-Ins
- •An Add-In Example
- •System Requirements
- •Using the CD
- •What’s on the CD
- •Troubleshooting
- •The Excel Help System
- •Microsoft Technical Support
- •Internet Newsgroups
- •Internet Web sites
- •End-User License Agreement

Part II: Working with Formulas and Functions
Working with Multicell Array Formulas
The preceding chapter introduced array formulas entered into multicell ranges. In this section, I present a few more array multicell formulas. Most of these formulas return some or all the values in a range, but rearranged in some way.
On the CD
The examples in this section are available on the companion CD-ROM. The file is named multi-cell array formulas.xlsx.
Returning only positive values from a range
The following array formula works with a single-column vertical range (named Data). The array formula is entered into a range that’s the same size as Data and returns only the positive values in the Data range. (Zeroes and negative numbers are ignored.)
{=INDEX(Data,SMALL(IF(Data>0,ROW(INDIRECT(“1:”&ROWS(Data)))),
ROW(INDIRECT(“1:”&ROWS(Data)))))}
As you can see in Figure 17.9, this formula works, but not perfectly. The Data range is A4:A22, and the array formula is entered into C4:C23. However, the array formula displays #NUM! error values for cells that don’t contain a value.
This modified array formula, entered into range E4:E23, uses the IFERROR function to avoid the error value display:
{=IFERROR(INDEX(Data,SMALL(IF(Data>0,ROW
(INDIRECT(“1:”&ROWS(Data)))),ROW
(INDIRECT(“1:”&ROWS(Data))))),””)}
The IFERROR function was introduced in Excel 2007. For compatibility with older versions, use this formula:
{=IF(ISERR(SMALL(IF(Data>0,ROW(INDIRECT(“1:”&ROWS(Data)))),ROW
(INDIRECT(“1:”&ROWS(Data))))),””,INDEX(Data,SMALL(IF
(Data>0,ROW(INDIRECT(“1:”&ROWS(Data)))),ROW(INDIRECT
(“1:”&ROWS(Data))))))}
Returning nonblank cells from a range
The following formula is a variation on the formula in the preceding section. This array formula works with a single-column vertical range named Data. The array formula is entered into a range of the same size as Data and returns only the nonblank cell in the Data range.
394

Chapter 17: Performing Magic with Array Formulas
{=IFERROR(INDEX(Data,SMALL(IF(Data<>””,ROW(INDIRECT
(“1:”&ROWS(Data)))),ROW(INDIRECT(“1:”&ROWS(Data))))),””)}
For compatibility with versions prior to Excel 2007, use this formula:
{=IF(ISERR(SMALL(IF(Data<>””,ROW(INDIRECT(“1:”&ROWS(Data)))),
ROW(INDIRECT(“1:”&ROWS(Data))))),””,INDEX(Data,SMALL(IF
(Data<>””,ROW(INDIRECT(“1:”&ROWS(Data)))),ROW(INDIRECT
(“1:”&ROWS(Data))))))}
FIGURE 17.9
Using an array formula to return only the positive values in a range.
Reversing the order of cells in a range
In Figure 17.10, cells C4:C13 contain a multicell array formula that reverses the order of the values in the range A4:A13 (which is named Data).
The array formula is
{=IF(INDEX(Data,ROWS(Data)-ROW(INDIRECT (“1:”&ROWS(Data)))+1)=””,””,INDEX(Data,ROWS(Data)-ROW(INDIRECT(“1 :”&ROWS(Data)))+1))}
395

Part II: Working with Formulas and Functions
FIGURE 17.10
A multicell array formula displays the entries in A4:A13 in reverse order.
Sorting a range of values dynamically
Figure 17.11 shows a data entry range in column A (named Data). As the user enters values into that range, the values are displayed sorted from largest to smallest in column C. The array formula in column C is rather simple:
{=LARGE(Data,ROW(INDIRECT(“1:”&ROWS(Data))))}
If you prefer to avoid the #NUM! error display, the formula gets a bit more complex:
{=IF(ISERR(LARGE(Data,ROW(INDIRECT(“1:”&ROWS(Data))))),
“”,LARGE(Data,ROW(INDIRECT(“1:”&ROWS(Data)))))}
Note that this formula works only with values. The companion CD-ROM has a similar array formula example that works only with text.
Returning a list of unique items in a range
If you have a single-column range named Data, the following array formula returns a list of the unique items in the range (the list with no duplicated items):
{=INDEX(Data,SMALL(IF(MATCH(Data,Data,0)=ROW(INDIRECT
(“1:”&ROWS(Data))),MATCH(Data,Data,0),””),ROW(INDIRECT
(“1:”&ROWS(Data)))))}
This formula doesn’t work if the Data range contains any blank cells. The unfilled cells of the array formula display #NUM!.
396

Chapter 17: Performing Magic with Array Formulas
The following modified version eliminates the #NUM! display by using the Excel 2007 IFERROR function.
{=IFERROR(INDEX(Data,SMALL(IF(MATCH(Data,Data,0)=ROW(INDIRECT
(“1:”&ROWS(data))),MATCH(Data,Data,0),””),ROW(INDIRECT
(“1:”&ROWS(Data))))),””)}
FIGURE 17.11
A multicell array formula displays the values in column A, sorted.
Figure 17.12 shows an example. Range A4:A22 s named Data, and the array formula is entered into range C4:C22. Range E4:E22 contains the array formula that uses the IFERROR function.
397

Part II: Working with Formulas and Functions
FIGURE 17.12
Using an array formula to return unique items from a list.
Displaying a calendar in a range
Figure 17.13 shows the results of one of my favorite multicell array formulas, a “live” calendar displayed in a range of cells. If you change the date at the top, the calendar recalculates to display the dates for the month and year.
On the CD
This workbook is available on the companion CD-ROM. The file is named array formula calendar.xlsx. In addition, you’ll find a workbook (yearly calendar.xlsx) that uses this technique to display a calendar for a complete year. n
After you create this calendar, you can easily copy it to other worksheets or workbooks.
To create this calendar in the range B2:H9, follow these steps:
1.Select B2:H2 and merge the cells by choosing Home Alignment Merge &
Center.
2.Enter a date into the merged range. The day of the month isn’t important.
3.Enter the abbreviated day names in the range B3:H3.
398

Chapter 17: Performing Magic with Array Formulas
4.Select B4:H9 and enter this array formula. Remember: To enter an array formula, press Ctrl+Shift+Enter (not just Enter).
{=IF(MONTH(DATE(YEAR(B2),MONTH(B2),1))<>MONTH(DATE(YEAR(B2), MONTH(B2),1)-(WEEKDAY(DATE(YEAR(B2),MONTH(B2),1))-1)+ {0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1),””, DATE(YEAR(B2),MONTH(B2),1)-(WEEKDAY(DATE(YEAR(B2),MONT H(B2),1))-1)+
{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1)}
5.Format the range B4:H9 to use this custom number format: d. This step formats the dates to show only the day. Use the Custom category in the Number tab of the Format Cells dialog box to specify this custom number format.
6.Adjust the column widths and format the cells as you like.
7.Change the month and year in cell B2. The calendar updates automatically.
After creating this calendar, you can copy the range to any other worksheet or workbook.
FIGURE 17.13
Displaying a calendar by using a single array formula.
The array formula actually returns date values, but the cells are formatted to display only the day portion of the date. Also, notice that the array formula uses array constants.
Cross-Reference
See Chapter 16 for more information about array constants. n
399

Part III
Creating Charts
and Graphics
The five chapters in this section deal with charts and graphics — including the new Sparkline graphics. You’ll discover how to use Excel’s graph-
ics capabilities to display your data in a chart. In addition, you’ll learn to use Excel’s other drawing tools to enhance your worksheets.
IN THIS PART
Chapter 18
Getting Started Making Charts
Chapter 19
Learning Advanced Charting
Chapter 20
Visualizing Data Using
Conditional Formatting
Chapter 21
Creating Sparkline Graphics
Chapter 22
Enhancing Your Work with Pictures and SmartArt