EXCEL Formule
EXCEL Formule
EXCEL Formule
Paul McFedries
Microsoft Excel 2019 Formulas and Functions
Published with the authorization of Microsoft Corporation by:
Pearson Education, Inc.
Copyright © 2019 by Pearson Education, Inc.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to
any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechani-
cal, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate con-
tacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/permissions/.
No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has
been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is
any liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-1-5093-0619-0
ISBN-10: 1-5093-0619-6
Library of Congress Control Number: 2019930661
1 19
Trademarks
Microsoft and the trademarks listed at http://www.microsoft.com on the “Trademarks” webpage are trademarks of the
Microsoft group of companies. All other marks are property of their respective owners.
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic
versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding
interests), please contact our corporate sales department at [email protected] or (800) 382-3419.
For government sales inquiries, please contact [email protected].
For questions about sales outside the U.S., please contact [email protected].
Editor-in-Chief: Brett Bartow
Executive Editor: Loretta Yates
Sponsoring Editor: Charvi Arora
Managing Editor: Sandra Schroeder
Senior Project Editor: Tracey Croom
Project Editor: Charlotte Kughen
Indexer: Cheryl Lenser
Proofreader: Gill Editorial Services
Technical Editor: Bob Umlas
Publishing Coordinator: Cindy Teeters
Cover Designer: Twist Creative, Seattle
Compositor: Bronkella Publishing LLC
Graphics: TJ Graham Art
To Karen and Chase
Contents at a Glance
Introduction xxiii
Index 443
v
Contents
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
viii Contents
Handling formula errors with IFERROR() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Using the formula error checker. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Choosing an error action. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Setting error checker options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
Auditing a worksheet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Understanding auditing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Tracing cell precedents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Tracing cell dependents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Tracing cell errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Removing tracer arrows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Evaluating formulas. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Watching cell values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
ix
Contents
The TEXT() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Displaying when a workbook was last updated. . . . . . . . . . . . . . . . . . . 89
Manipulating text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Removing unwanted characters from a string. . . . . . . . . . . . . . . . . . . . 89
The TEXTJOIN() function: Concatenating text with a delimiter. . . . . 91
The REPT() function: Repeating a character or string. . . . . . . . . . . . . 92
Extracting a substring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Converting text to sentence case. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
A date-conversion formula. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Searching for substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
The FIND() and SEARCH() functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Extracting a first name or last name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Extracting first name, last name, and middle initial . . . . . . . . . . . . . . . 99
Determining the column letter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Substituting one substring for another. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
The REPLACE() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
The SUBSTITUTE() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Removing a character from a string. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Removing two different characters from a string. . . . . . . . . . . . . . . . 102
Removing line feeds. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
xi
Contents
The INT() and TRUNC() functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Using rounding to prevent calculation errors. . . . . . . . . . . . . . . . . . . . 190
Summing values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
The SUM() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
The SUMIF() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Summing only the positive or negative values in a range. . . . . . . . . 193
The SUMIFS() function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Calculating cumulative totals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
The MOD() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
A better formula for time differences. . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Summing every nth row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Determining whether a year is a leap year. . . . . . . . . . . . . . . . . . . . . . . 196
Creating ledger shading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Generating random numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
The RAND() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
The RANDBETWEEN() function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
The RANDARRAY() function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Creating increasing random numbers with the SEQUENCE()
function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
xii Contents
Liquidity formulas. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Accounts receivable ratios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Accounts payable ratios. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Working capital . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Liquidity ratios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Liquidity index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
xiii
Contents
Chapter 12 Building inferential statistical formulas 245
Understanding inferential statistics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Sampling data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Extracting a periodic sample. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Extracting a random sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Determining whether two variables are related . . . . . . . . . . . . . . . . . . . . . . . 249
Calculating covariance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Calculating correlation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Working with probability distributions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Calculating probability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Discrete probability distributions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Understanding the normal distribution and the NORM.DIST()
function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Determining confidence intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Hypothesis testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
xiv Contents
Calculating the principal and interest. . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Calculating interest costs, part II. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Calculating cumulative principal and interest. . . . . . . . . . . . . . . . . . . . . 311
Building a loan amortization schedule. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Building a fixed-rate amortization schedule. . . . . . . . . . . . . . . . . . . . . 312
Building a dynamic amortization schedule. . . . . . . . . . . . . . . . . . . . . . 313
Calculating the term of a loan. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Calculating the interest rate required for a loan . . . . . . . . . . . . . . . . . . . . . . . 317
Calculating how much you can borrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
xv
Contents
Net present value with varying cash flows. . . . . . . . . . . . . . . . . . . . . . . 347
Net present value with nonperiodic cash flows. . . . . . . . . . . . . . . . . . 348
Calculating the payback period . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Simple undiscounted payback period. . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Exact undiscounted payback point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Discounted payback period. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Calculating the internal rate of return. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Using the IRR() function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Calculating the internal rate of return for nonperiodic
cash flows. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Calculating multiple internal rates of return. . . . . . . . . . . . . . . . . . . . . 353
xvi Contents
Chapter 18 Analyzing data with PivotTables 381
Working with PivotTable subtotals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Hiding PivotTable grand totals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Hiding PivotTable subtotals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Customizing the subtotal calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Changing the value field summary calculation . . . . . . . . . . . . . . . . . . . . . . . . 383
Using a difference summary calculation. . . . . . . . . . . . . . . . . . . . . . . . 383
Toggling the difference calculation with VBA. . . . . . . . . . . . . . . . . . . . 385
Using a percentage summary calculation . . . . . . . . . . . . . . . . . . . . . . . 385
Using a running total summary calculation. . . . . . . . . . . . . . . . . . . . . . 388
Using an index summary calculation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Creating custom PivotTable calculations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Creating a calculated field. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Creating a calculated item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Using PivotTable results in a worksheet formula. . . . . . . . . . . . . . . . . . . . . . . 395
xvii
Contents
Merging scenarios. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Generating a summary report. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Deleting a scenario. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
xviii Contents
Acknowledgments
Substitute damn every time you’re inclined to write very; your editor will delete it and the
writing will be just as it should be.
—Mark Twain
I didn’t follow Mark Twain’s advice in this book (the word very appears throughout), but
if my writing still appears “just as it should be,” then it’s because of the keen minds and
sharp linguistic eyes of the editors at Pearson Education. Near the front of the book you’ll
find a long list of the hard-working professionals whose fingers made it into this particular
paper pie. However, there are a few folks I worked with directly, so I’d like to single them
out for extra credit. A big, heaping helping of thanks goes out to executive editor Loretta
Yates, project editor Charlotte Kughen, and technical editor Bob Umlas.
xix
Acknowledgments
About the author
Paul McFedries is an Excel expert and full-time technical writer. Paul has been authoring
computer books since 1991 and has more than 95 books to his credit, which combined
have sold more than 4 million copies worldwide. His titles include the Que Publishing
books My Office 2016, Windows 10 In Depth (with coauthor Brian Knittel), and PCs for
Grownups, as well as the Sams Publishing book Windows 7 Unleashed. Paul is also the
proprietor of Word Spy (www.wordspy.com), a website devoted to lexpionage, the
sleuthing of new words and phrases that have entered the English language. Please drop
by Paul’s personal website at mcfedries.com or follow Paul on Twitter, at twitter.com/
paulmcf and twitter.com/wordspy.
For companion files, you can visit the book's page at mcfedries.com,
https://mcfedries.com/books/book.php?title=excel-2019-formulas-and-functions, or
at the Microsoft Press Store, MicrosoftPressStore.com/Excel2019FormulasFunctions/
downloads.
Troubleshooting formulas
In this chapter, you will:
• Decipher the formula error values that Excel displays
• Learn how to fix a few other common formula error types
• Handle formula errors gracefully with the IFERROR() function
• Diagnose formula problems using Excel’s Formula Error Checker
• Learn how to use Excel’s worksheet auditing tools
D espite your best efforts, the odd error might appear in your formulas from time to time. Such er-
rors can be mathematical (for example, dividing by zero), or Excel might simply be incapable of
interpreting the formula. In the latter case, problems can be caught while you’re entering the formula.
For example, if you try to enter a formula that has unbalanced parentheses, Excel doesn’t accept the
entry, and it displays an error message. Other errors are more insidious. For example, your formula
might appear to be working—that is, it might return a value—but the result might be incorrect be-
cause the data is flawed or because your formula has referenced the wrong cell or range.
Whatever the error and whatever the cause, formula woes need to be worked out because you or
someone else in your company is likely depending on your models to produce accurate results. Don’t
fall into the trap of thinking that your spreadsheets are problem free. A recent University of Hawaii
study found that 50% of spreadsheets contained errors that led to “significant miscalculations.” And
the more complex the model, the greater the chance that errors can creep in. A KPMG study from a few
years ago found that a staggering 90% of spreadsheets used for tax calculations contained errors.
The good news is that fixing formula flaws need not be drudgery. With a bit of know-how and
Excel’s top-notch troubleshooting tools, sniffing out and repairing model maladies isn’t hard. This
chapter tells you everything you need to know.
Tip If you try to enter an incorrect formula, Excel won’t let you do anything else until you
either fix the problem or cancel the operation (which means you lose your formula). If the
formula is complex, you might not be able to see the problem right away. Instead of delet-
ing all your work, place an apostrophe (') at the beginning of the formula to convert it to
text. This way, you can save your work while you try to figure out the problem.
49
Understanding Excel’s error values
When you enter or edit a formula or change one of the formula’s input values, Excel might show an er-
ror value as the formula result. Excel has eleven different error values: #CALC!, #DIV/0!, #FIELD!, #N/A,
#NAME?, #NULL!, #NUM!, #REF!, #SPILL!, #UNKNOWN!, and #VALUE!. The next few sections give you a
detailed look at these error values and offer suggestions for dealing with them.
#CALC!
The new #CALC! error appears when Excel’s calculation engine comes across a formula or expression
that it doesn’t support. Examples include one of the following:
#DIV/0!
The #DIV/0! error almost always means that the cell’s formula is trying to divide by zero, a mathemati-
cal no-no. The cause is usually a reference to a cell that either is blank or contains the value 0. Check
the cell’s precedents (the cells that are directly or indirectly referenced in the formula; see “Auditing
a worksheet,” later in this chapter) to look for possible culprits. You’ll also see #DIV/0! if you enter an
inappropriate argument in some functions. MOD(), for example, returns #DIV/0! if the second argu-
ment is 0.
That Excel treats blank cells as the value 0 can pose problems in a worksheet that requires the user
to fill in the data. If your formula requires division by one of the temporarily blank cells, it will show
#DIV/0! as the result, possibly confusing the user. You can get around this by telling Excel not to per-
form the calculation if the cell used as the divisor is 0. This is done with the IF() worksheet function,
which I discuss in detail in Chapter 6, “Working with logical and information functions.” (For an even
better way to deal with potential formula errors, see “Handling formula errors with IFERROR(),” later
in this chapter.) For example, consider the following formula, which uses named cells to calculate gross
margin:
=GrossProfit / Sales
To prevent the #DIV/0! error from appearing if the Sales cell is blank (or 0), you’d modify the for-
mula as follows:
If the value of the Sales cell is 0, the formula returns the empty string; otherwise, it performs the
calculation.
■■ Your formula includes a data-type reference to a field that isn’t found in a linked data type.
For example, if cell A1 contains a Stocks data type and your formula references A1.[52-week
high], you’ll get a #FIELD! error because the 52-week high field doesn’t exist. In this example,
you can solve the problem by removing the dash: A1.[52 week high].
■■ Your formula includes a data-type reference (for example, A1.Price for a Stocks data type) on a
cell that doesn’t use a linked data type.
■■ Your formula includes a data-type reference (for example, A1.Description for a Stocks data
type) on a cell that doesn’t have any data for the referenced field.
#N/A
The #N/A error value is short for not available, and it means that the formula couldn’t return a legiti-
mate result. You usually see #N/A when you use an inappropriate argument (or when you omit a re-
quired argument) in a function. HLOOKUP() and VLOOKUP(), for example (see Chapter 7, “Working with
lookup functions”), return #N/A if the lookup value is smaller than the first value in the lookup range.
To solve the problem, first check the formula’s input cells to see whether any of them are displaying
the #N/A error. If so, that’s why your formula is returning the same error; the problem actually lies in the
input cell. When you’ve found where the error originates, examine the formula’s operands to look for
inappropriate data types. In particular, check the arguments used in each function to ensure that they
make sense for the function and that no required arguments are missing.
Note It’s common in spreadsheet work to purposely generate an #N/A! error to show that
a particular cell value isn’t currently available. For example, you might be waiting for budget
figures from one or more divisions or for the final numbers from month- or year-end. In
such a case, you enter =NA() into the cell. You fix this “problem” by replacing the NA() func-
tion with the appropriate data when it arrives.
#NAME?
The #NAME? error appears when Excel doesn’t recognize a name you used in a formula or when it inter-
prets text within the formula as an undefined name. This means that the #NAME? error pops up in a wide
variety of circumstances:
■■ You entered a reference to a range on another worksheet and didn’t enclose the sheet name in
single quotation marks.
Tip When entering function names and defined names, use all lowercase letters. If Excel
recognizes a name, it converts the function to all uppercase and the defined name to its
original case. If no conversion occurs, you know that you misspelled the name, you haven’t
defined it yet, or you’re using a function from an add-in that isn’t loaded.
Remember that you also can use these commands to enter functions and names safely:
Formulas > Insert Function (or select Shift+F3); Formulas > Use In Formula; or Formulas
> Use In Formula > Paste Names (or select F3).
These are mostly syntax errors, so fixing them means double-checking your formula and correct-
ing range name or function name misspellings, or inserting missing quotation marks or colons. Also,
be sure to define any range names you use and to install the appropriate add-in modules for functions
you use.
Redefining the original range name becomes problematic if you can’t remember the appropriate
range coordinates. This is why it’s always a good idea to paste a list of range names and their references
into each of your worksheets (select Formulas > Use In Formula > Paste Names > Paste List).
If you don’t need this safety net, you can force Excel to convert deleted range names into their cell
references. Here are the steps to follow:
1. Select File > Options to display the Excel Options dialog box.
2. Select Advanced.
3. In the Lotus Compatibility Settings For section, use the list to select the worksheet you want
to use.
5. Select OK.
Excel now treats your formula entries the same way Lotus 1-2-3 did way back in days of yore. Specifi-
cally, in formulas that use a deleted range name, the name automatically gets converted to its appro-
priate range reference. As an added bonus, Excel also performs the following automatic conversions:
■■ If you enter a range reference in a formula, the reference gets converted to a range name (pro-
vided that a name exists, of course).
■■ If you define a name for a range, Excel converts any existing range references into the new name.
Caution The treatment of formulas in the Lotus 1-2-3 manner only applies to formulas that
you create after you select the Transition Formula Entry check box.
#NULL!
Excel displays the #NULL! error in a very specific case: when you use the intersection operator (a space)
on two ranges that have no cells in common. For example, because the ranges A1:B2 and C3:D4 have no
common cells, the following formula returns the #NULL! error:
=SUM(A1:B2 C3:D4)
Check your range coordinates to ensure that they’re accurate. Also, check to see if one of the ranges
has been moved, causing the two ranges in your formula to no longer intersect.
#NUM!
The #NUM! error means there’s a problem with a number in a formula. This almost always means that
you entered an invalid argument in a math or trig function. For example, perhaps you entered a
negative number as the argument for the SQRT() or LOG() function. Check the formula’s input cells—
particularly those that are used as arguments for mathematical functions—to make sure the values are
appropriate.
The #NUM! error also appears if you’re using iteration (or a function that uses iteration; see Chapter
2, “Creating advanced formulas”), and Excel can’t calculate a result. There could be no solution to the
problem, or you might need to adjust the iteration parameters.
#REF!
The #REF! error means that a formula contains an invalid cell reference, which is usually caused by one
of the following actions:
■■ You deleted a cell to which the formula refers. You need to add the cell back in or adjust the
formula reference.
■■ Your formula references a nonexistent cell address, such as B0. This can happen if you cut or
copy a formula that uses relative references and paste it in such a way that the invalid cell ad-
dress is created. For example, suppose that your formula references cell B1. If you cut or copy
the cell containing the formula and paste it one row higher, the reference to B1 becomes invalid
because Excel can’t move the cell reference up one row.
#SPILL!
You see the new #SPILL! error when a dynamic array formula or function that needs to spill data into
one or more adjacent cells encounters a non-empty cell in the spill range. (See Chapter 2 to learn more
about spill ranges.) You have two ways to handle a #SPILL! error:
■■ Move the formula that needs the spill range to a new location where the spill range is empty.
In both cases, Excel removes the #SPILL! error and spills the formula result in the new spill range.
#UNKNOWN!
If you see the new #UNKNOWN! error, it means your formula or expression is referencing a data type that
isn’t supported in your version of Excel. This most often means that the reference is to a data type that
was added to a later version of Excel, so the only way to resolve the error is to upgrade to a version of
Excel that supports the data type.
#VALUE!
When Excel generates a #VALUE! error, it means you’ve used an inappropriate argument in a func-
tion. This is most often caused by using the wrong data type. For example, you might have entered or
referenced a string value instead of a numeric value. Similarly, you might have used a range reference
in a function argument that requires a single cell or value. Excel also generates this error if you use a
value that’s larger or smaller than Excel can handle. In all these cases, you solve the problem by double-
checking your function arguments to find and edit the inappropriate arguments.
Note Excel can work with values between –1E–307 and 1E+307.
FIGURE 3-1 If you miss a parenthesis, Excel attempts to fix the problem and displays this dialog box to ask if you
want to accept the correction.
Caution Excel doesn’t always fix missing parentheses correctly. It tends to add the missing
parenthesis to the end of the formula, which is often not what you want. Therefore, always
check Excel’s proposed solution carefully before accepting it.
To help you avoid missing or mismatched parentheses, Excel provides two visual clues in the formula
itself when you’re editing it:
■■ The first clue occurs when you type a right parenthesis. Excel temporarily bolds both the right
parenthesis and its corresponding left parenthesis. If you type what you think is the last right
parenthesis but Excel doesn’t bold the first left parenthesis, your parentheses are unbalanced.
■■ The second clue occurs when you use the left and right arrow keys to navigate a formula. When
you cross over a parenthesis, Excel bolds the other parenthesis in the pair.
■■ Calculate complex formulas one term at a time. In the formula bar, select the expression
you want to calculate and then select F9. Excel converts the expression into its value. Make sure
that you select the Esc key when you’re done to avoid entering the formula with just the calcu-
lated values.
■■ Evaluate the formula. You can step through the various parts of a formula, a technique that I
describe later in this chapter (see “Evaluating formulas”).
■■ Break up long or complex formulas. One of the most problematic aspects of formula
troubleshooting is making sense out of long formulas. The previous techniques can help (by en-
abling you to evaluate parts of the formula), but it’s usually best to keep your formulas as short
as you can at first. When you get things working properly, you often can combine formulas for a
more efficient model.
■■ Recalculate all formulas. A formula might display the wrong result because other formulas on
which it depends need to be recalculated. This is particularly true if one or more of those formu-
las use custom VBA functions. Select Shift+F9 to recalculate all worksheet formulas.
■■ Watch out for nonblank “blank” cells. A cell might appear to be blank but actually contain
data or even a formula. For example, some users “clear” a cell by selecting the spacebar, and
Excel then treats the cell as nonblank. Similarly, some formulas return an empty string instead
of a value. (For example, see the IF() function formula earlier in this chapter for avoiding the
#DIV/0! error.)
■■ Watch unseen values. In a large model, your formula could be using cells that you can’t see
because they’re offscreen or on another sheet. Excel’s Watch Window enables you to keep an
eye on the current value of one or more cells. To learn about the Watch Window, see “Watching
cell values,” later in this chapter.
■■ Directly: The formula explicitly references its own cell. For example, a circular reference would
result if the following formula were entered into cell A1:
=A1+A2
■■ A circular reference would result if cell A5 referred to cell A1, as in this example:
=SUM(A1:D1)
When Excel detects a circular reference, it displays the dialog box shown in Figure 3-2.
FIGURE 3-2 If you attempt to enter a formula that contains a circular reference, Excel displays this dialog box.
When you select OK, Excel displays tracer arrows that connect the cells involved in the circular refer-
ence. (Tracers are discussed in detail later in this chapter; see “Auditing a worksheet.”) Knowing which
cells are involved enables you to correct the formula in one of them to solve the problem.
If you want to handle errors gracefully in your worksheets, it’s often best to assume that any error
can occur. Fortunately, that doesn’t mean you have to construct complex tests using deeply nested
IF() functions that check for every error type (#DIV/0!, #N/A, and so on). Instead, Excel enables you to
use a simple test for any error by offering the IFERROR() function:
IFERROR(value, value_if_error)
Note If you want to handle the specific case of the #N/A error, use the IFNA(value,
value_if_na) function. Here, value is the expression that you’re testing for the #N/A error, and
value_if_na is the value to return if value returns the #N/A error.
Excel has a similar feature: the formula error checker. Like the grammar checker, the formula error
checker uses a set of rules to determine correctness, and it operates in the background to monitor your
formulas. If it detects something amiss, it displays an error indicator—a green triangle—in the upper-
left corner of the cell containing the formula, as shown in Figure 3-3.
Error indicator
FIGURE 3-3 If Excel’s formula error checker detects a problem, it displays a green triangle in the upper-left corner
of the formula’s cell.
■■ Corrective action: This is a command (the name of which depends on the type of error) that
Excel believes either will fix the problem or help you troubleshoot the error. In Figure 3-4, for
■■ Help On This Error: Select this option to get information on the error via the Excel Help sys-
tem.
■■ Edit In Formula Bar: Select this option to display the formula in Edit mode in the formula bar.
You can then fix the problem by editing the formula.
■■ Error-Checking Options: Select this option to display the Formulas tab of the Excel Options
dialog box (discussed next).
FIGURE 3-4 Select the cell containing the error and then move the mouse pointer over the formula error icon to
see a description of the error.
■■ Select File > Options > Formulas to open the Excel Options dialog box and display the For-
mulas tab.
■■ Select Error-Checking Options in the formula error icon’s drop-down menu (as described in
the previous section).
Either way, the options appear in the Error Checking and Error Checking Rules sections in the For-
mulas tab, as shown in Figure 3-5.
■■ Enable Background Error Checking: This check box toggles the formula error checker’s back-
ground operation on and off. If you turn off the background checking, you can run a check at
any time by choosing Formulas > Error Checking.
■■ Indicate Errors Using This Color: Use this color palette to select the color of the error indica-
tor.
■■ Reset Ignored Errors: If you’ve ignored one or more errors, you can redisplay the error indica-
tors by selecting this button.
■■ Cells Containing Formulas That Result In An Error: When this check box is selected, the
formula error checker flags formulas that evaluate to #DIV/0!, #NAME?, or any of the other error
values discussed earlier.
■■ Inconsistent Calculated Column Formula In Tables: When this check box is selected, Excel
examines the formulas in a table’s calculated column and flags any cell that contains a formula
with a different structure than the other cells in the column. The formula error icon for this error
includes the command Restore To Calculated Column Formula, which enables you to update
the formula so that it’s consistent with the rest of the column.
■■ Cells Containing Years Represented As 2 Digits: When this check box is selected, the for-
mula error checker flags formulas that contain date text strings in which the year contains only
two digits (a possibly ambiguous situation because the string could refer to a date in either the
1900s or the 2000s). In such a case, the list of options supplied in the formula error icon contains
two commands—Convert XX To 19XX and Convert XX To 20XX—that enable you to convert
the two-digit year to a four-digit year.
■■ Formulas Which Omit Cells In A Region: When this check box is selected, the formula error
checker flags formulas that omit cells that are adjacent to a range referenced in the formula. For
example, suppose that the formula is =AVERAGE(C4:C21), where C4:C21 is a range of numeric
values. If cell C3 also contains a numeric value, the formula error checker flags the formula to
alert you to the possibility that you missed including cell C3 in the formula. Figure 3-6 shows
this example. In such a case, the list of options supplied in the formula error icon will contain the
command Update Formula To Include Cells to adjust the formula automatically.
FIGURE 3-6 The formula error checker can flag formulas that omit cells that are adjacent to a range referenced by
the formula. In this case, the formula in C23 should include cell C3.
■■ Unlocked Cells Containing Formulas: When this check box is selected, the formula error
checker flags formulas that reside in unlocked cells. This isn’t an error so much as a warning that
other people could tamper with the formula even after you have protected the sheet. In such a
case, the list of options supplied in the formula error icon will contain the command Lock Cell
to lock the cell and prevent users from changing the formula after you protect the sheet.
■■ Formulas Referring To Empty Cells: When this check box is selected, the formula error
checker flags formulas that reference empty cells. In such a case, the list of options supplied in
the formula error icon will contain the command Trace Empty Cell to enable you to find the
■■ Data Entered In A Table Is Invalid: When this check box is selected, the formula error checker
flags cells that violate a table’s data-validation rules. This can happen if you set up a data-
validation rule with only a Warning or Information style, in which case the user can still opt to
enter the invalid data. In such cases, the formula error checker will flag the cells that contain
invalid data. The formula error icon list includes the Display Type Information command,
which shows the data-validation rule that the cell data violates.
Auditing a worksheet
As you’ve seen, some formula errors result from referencing other cells that contain errors or inappro-
priate values. The first step in troubleshooting these kinds of formula problems is to determine which
cell (or group of cells) is causing an error. This is straightforward if the formula references only a single
cell, but it gets progressively more difficult as the number of references increases. (Another complicat-
ing factor is the use of range names because it won’t be obvious which range each name is referenc-
ing.)
To determine which cells are wreaking havoc on your formulas, you can use Excel’s auditing features
to visualize and trace a formula’s input values and error sources.
Understanding auditing
Excel’s formula-auditing features operate by creating tracers—arrows that literally point out the cells
involved in a formula. You can use tracers to find three kinds of cells:
■■ Precedents: These are cells that are directly or indirectly referenced in a formula. For example,
suppose that cell B4 contains the formula =B2; then B2 is a direct precedent of B4. Now suppose
that cell B2 contains the formula =A2/2; this makes A2 a direct precedent of B2, but it’s also an
indirect precedent of cell B4.
■■ Dependents: These are cells that are directly or indirectly referenced by a formula in another
cell. In the preceding example, cell B2 is a direct dependent of A2, and B4 is an indirect depen-
dent of A2.
■■ Errors: These are cells that contain an error value and are directly or indirectly referenced in a
formula (and therefore cause the same error to appear in the formula).
■■ Cell B4 contains the formula =B2, and B2 contains =A2/2. The arrows (they’re blue onscreen)
point out the precedents (direct and indirect) of B4.
■■ Cell G4 contains the formula =Sheet5!A1. Excel displays the dashed arrow with the worksheet
icon whenever the precedent or dependent exists on a different worksheet.
FIGURE 3-7 This worksheet demonstrates the three types of tracer arrows.
1. Select the cell that contains the formula whose precedents you want to trace.
2. Select Formulas > Trace Precedents. Excel adds a tracer arrow to each direct precedent.
Tip You also can trace precedents by double-clicking the cell, provided that you turn off
in-cell editing. You do this by choosing File > Options > Advanced and then deselecting
the Allow Editing Directly In Cells check box. Now when you double-click a cell, Excel se-
lects the formula’s precedents.
2. Select Formulas > Trace Dependents. Excel adds a tracer arrow to each direct dependent.
1. Select the cell that contains the error you want to trace.
2. Select Formulas > Error Checking > Trace Error. Excel adds a tracer arrow to each cell that
produced the error.
■■ To remove all the tracer arrows, select Formulas > Remove Arrows.
■■ To remove precedent arrows one level at a time, select Formulas, drop down the Remove Ar-
rows list, and select Remove Precedent Arrows.
■■ To remove dependent arrows one level at a time, select Formulas, drop down the Remove Ar-
rows list, and select Remove Dependent Arrows.
Evaluating formulas
Earlier, you learned that you can troubleshoot a wonky formula by evaluating parts of it. You do this
by selecting the part of the formula you want to evaluate and then selecting F9. This works fine, but it
can be tedious in a long or complex formula, and there’s always a danger that you might accidentally
confirm a partially evaluated formula and lose your work.
A better solution is to use Excel’s Evaluate Formula feature. It does the same thing as the F9 tech-
nique, but it’s easier and safer. Here’s how it works:
1. Select the cell that contains the formula you want to evaluate.
2. Select Formulas > Evaluate Formula. Excel displays the Evaluate Formula dialog box.
3. The current term in the formula is underlined in the Evaluation box. At each step, you select
from one or more of the following buttons:
5. Select Close.
This is a problem because there’s no easy way to determine the current contents or value of the
unseen precedent. If you’re having a problem, troubleshooting requires that you track down the far-off
precedent to see if it might be the culprit. That’s bad enough with a single unseen cell, but what if your
formula refers to 5 or 10 such cells? And what if those cells are scattered in different worksheets and
workbooks?
This level of hassle—not at all uncommon in the spreadsheet world—was no doubt the inspira-
tion behind an elegant solution: the Watch Window. This window enables you to keep tabs on both
the value and the formula in any cell in any worksheet in any open workbook. Here’s how you set up a
watch:
1. Switch to the workbook that contains the cell or cells you want to watch.
2. Select Formulas > Watch Window. Excel displays the Watch Window.
3. Select Add Watch. Excel displays the Add Watch dialog box.
4. Either select the cell you want to watch or type in a reference formula for the cell (for example,
=A1). Note that you can select a range to add multiple cells to the Watch Window.
5. Select Add. Excel adds the cell or cells to the Watch Window, as shown in Figure 3-9.
When you no longer need a watch, you should remove it to avoid cluttering the Watch Window. To
remove a watch, select Formulas > Watch Window to open the Watch Window, select the watch, and
then select Delete Watch.
443
add-ins
444
calculated fields
445
calculated items
446
changing
447
changing
448
customizing PivotTable subtotal calculations
449
custom PivotTable calculations
450
discount formulas
451
discount formulas
452
feasible solutions
453
#FIELD! error value
454
formulas
455
formulas
456
functions
457
functions
458
histograms
G H
GCD( ) function, 184 hiding
generating fields, 362
account numbers, 96, 102-103 PivotTable grand totals, 382
ANSI character set, 81-82 PivotTable subtotals, 382
random letters, 200 histograms, 93
459
HLOOKUP() function
HLOOKUP( ) function, 31, 136, 141-142 INDEX() function, 31, 47, 136, 147
exact-match lookups, 144-146 list boxes, looking up values, 148
range lookups, 142-144 lookup column, specifying, 148-149
holidays, calculating, 167-168, 189 multiple-column lookups, 150-151
HOUR( ) function, 173-174 row-and-column lookups, 149-150
hurdle rate, 346 INDIRECT() function, 310
HYPGEOM.DIST( ) function, 256 inferential statistics, 245-246
hypergeometric distributions, 256 confidence intervals, 261-262
hypothesis testing, 263-264 correlation, 251-252
covariance, 250-251
hypothesis testing, 263-264
normal distribution, 257-258
I percentiles, 259
shape of curve, 260-261
IF( ) function, 70, 106, 143
standard scores, 258-259
aging overdue invoices, 123-124
probability distributions, 252
applying conditions across ranges, 116
binomial, 255
avoiding
calculating, 253-255
#DIV/0 errors, 50
hypergeometric, 256
division by zero, 109
Poisson, 256-257
weekend due dates, 122-123
sampling data, 246-247
combining with arrays, 116-121
periodic samples, 247-248
conditional formatting with, 114-115
random samples, 249
counting occurrences in ranges, 119-120
finding row numbers in lists, 120-121 inflation, 340-341
handling FALSE results, 108 INFO() function, 70, 125, 129-130
multiple logical tests with, 109-115 information functions
nesting, 109-110 CELL(), 125-127
operations on cells that meet condition, ERROR.TYPE(), 128-129
117-118 INFO(), 129-130
simple version, 106-107 ISxxx( ), 130, 132-133
IFERROR( ) function, 57-58, 106 list of, 125
IFNA( ) function, 58, 106, 143 SHEET(), 130
SHEETS(), 130
IFS( ) function, 106, 110-111
initial deposit, calculating for investment goals,
ignoring errors in ranges, 132-133
333
in-cell drop-down lists, exact-match lookups
input modes, 4-5
and, 145-146
Insert Function feature, 74-76
income investing, rental properties versus,
342-343 inserting
degree symbol, 89
incorrect formula results, troubleshooting, 56
dialog box controls, 43
independent variables, 246, 265
check boxes, 46
index summary calculations, 389-391
combo boxes, 46-47
460
IPMT() function
461
IRR() function
462
lump sum future value
463
manual recalculation
464
NPV() function
465
#NULL! error value
O
with MONTH() function, 159
with WEEKDAY() function, 160
objective cells in Solver, 422 with WEEKNUM() function, 160
ODD( ) function, 184, 189 with WORKDAY() function, 161
with WORKDAY.INTL() function, 162-163
odd rows, adding, 196
with YEAR() function, 159
OFFSET( ) function, 246-247
parts of times, returning, 174
extracting periodic samples, 247-248
with HOUR() function, 174
extracting random samples, 249
with MINUTE() function, 175
one-input data tables, setup, 400-402
with SECOND() function, 175
operating costs, 355-356
pasting range names into formulas, 16-17
operations research, 421
pausing Goal Seek, 407
operators
payables. See accounts payable ratios
arithmetic, 5-6
payback period, calculating, 349
comparison, 6
discounted, 351
for constraints, 427
exact undiscounted, 350-351
order of precedence, 7-9
simple undiscounted, 349-350
reference, 6
text, 6 payments
defined, 306
optimizing product margin, 408-409
loan payments, calculating, 306-312
option buttons
mortgage payments, allowing principal
inserting, 45
paydowns, 321-323
integrating CHOOSE( ) function with,
PEARSON() function, 229
139-140
percentage summary calculations, 385-387
options for error checker, setting, 59-62
percentile
order of precedence, 7-9
calculating, 239, 259
OR( ) function, 106, 113-114
defined, 238
looking up list values, 118-119
PERCENTILE.EXC() function, 239
overdue invoices, aging, 123-124
PERCENTILE.INC() function, 239
466
PRODUCT() function
467
projections
468
returning
469
return on fixed assets
470
sorting
471
sorting
472
SUMSQ() function
473
SUMX2MY2() function
T
TAN() function, 186
TANH() function, 186
T( ) function, 80 target cells in Solver, 422
T.TEST( ) function, 264 tax rates, returning, 143-144
table formulas, entering, 373-374 term of loan, calculating, 315-317
table functions text
advantages of, 375 character codes, 80-81
analyzing table of defects, 378-379 CHAR() function, 81-83
DAVERAGE( ), 377 CODE() function, 83
DGET(), 377-378 concatenating with delimiter, 91
DSUM(), 375 converting, 84
entering, 376 formulas to, 49
FILTER( ), 370 with LOWER() function, 84
list of, 376 with NUMBERVALUE() function, 85
SORT( ), 364 with PROPER() function, 84
SORTBY( ), 364-365 to sentence case, 95
syntax of, 375-376 with UPPER() function, 84
UNIQUE( ), 371 defined, 79
table of defects, analyzing, 378-379 formatting, 85
table ranges, 361 with DOLLAR() function, 86
table specifiers, 371-373 with FIXED() function, 87
with TEXT() function, 87-89
TABLE( ) function, 405
repeating with REPT() function, 92-93
tables. See also data tables; PivotTables
text formulas, operators for, 6
defined, 361
filtering, 365-366 text functions
with complex criteria, 366-369 CELL(), 99-100
with computed criteria, 369-370 CHAR(), 81-83
with FILTER( ) function, 370 CLEAN(), 90, 103
with UNIQUE( ) function, 371 CODE(), 83
lookup tables, 136-137 COLUMN(), 99-100
sorting, 361 DOLLAR(), 86
without articles, 363-364 FIND(), 97-99
with formulas in, 362 FIXED(), 87
LEFT(), 94
LEN(), 90
474
trendlines
475
trendlines
476
worksheets
#VALUE! error value, 54, 248 weekdays, returning nth occurrence in month,
VALUE( ) function, 80 165-167
values weekend due dates, avoiding, 122-123
adding, 192 WEEKNUM() function, 157, 160
with SUM( ) function, 192, 194-195 weighted averages, 390
with SUMIF( ) function, 193 weighted mean, calculating, 235-236
with SUMIFS( ) function, 193-194 weighted questionnaire results, calculating, 139
categorizing by, 112-113 what-if analysis, 399-400
converting formulas to, 15-16 data tables
sorting randomly, 200-201 adding formulas to, 402-403
VARA( ) function, 241 editing, 405
variable cells in Solver, 422 one-input setup, 400-402
variable costs, 211 two-input setup, 403-405
variable interest rates, calculating future value wildcard characters in MATCH() function, 147
for investment goals, 334 workbooks
variable-rate mortgage amortization displaying last updated date, 89
schedules, building, 320-321 linking, 21
variables WORKDAY() function, 123, 157, 161
defined, 246 WORKDAY.INTL() function, 162-163
measures of association, 249-250 WORKDAY.INTO() function, 157
types of, 246 working capital, 224-225
variance, calculating, 240-241 working capital ratio, 226
VARPA( ) function, 241 working capital turnover, 225
VAR.P( ) function, 241 worksheets
VAR.S( ) function, 241 account receivable aging worksheet,
varying cash flows, net present value with, building, 122-124
347-348 adding scenarios to, 414-415
viewing auditing, 62-63
current input mode, 5 dependent tracing, 63
formulas, 15 error cell tracing, 64
VLOOKUP( ) function, 32, 136, 140-141 evaluating formulas, 64-65
exact-match lookups, 144-146 precedent tracing, 63
range lookups, 142-144 removing tracer arrows, 64
setting Watch Windows, 65-66
dialog box controls
W check boxes, 46
combo boxes, 46-47
watching cell values, 65-66 group boxes, 44
Watch Windows, setting, 65-66 inserting, 43
WEEKDAY( ) function, 122, 137, 157, 160, 165-167 linking to cells, 43
477
worksheets
478