Making Your Formulas Check for Errors

by Allen Wyatt
(last updated October 7, 2017)

1

It is often helpful to check if a cell contains an error condition so that your formula can know how to calculate results that may be dependent on that cell. Excel provides the IFERROR function to help determine this information. The purpose of this function is to help simplify how you check for potential errors in your formulas. Consider a rather simple example:

=B8/B9

In most instances this formula will return a good result—unless cell B9 contains a zero value. In that case, Excel returns a #DIV/0! error. The traditional approach to trap this potentiality is to use the ISERROR function in this manner:

=IF(ISERROR(B8/B9),0,B8/B9)

The ISERROR function returns either True or False, depending on whether the expression being evaluated returns an error or not. The surrounding IF function can then act upon the value returned by ISERROR to determine what should be displayed.

The problem with this approach is that it is rather convoluted. Note, for instance, that your evaluation (B8/B9) needs to be included twice in the full formula. While that may not seem problematic with such a simple evaluation, with longer formulas it can be a real pain—at a minimum it makes your overall formula twice as long as it should be and provides two formulas that need to be kept in sync when you make changes.

This is where the IFERROR function comes into play. It helps simplify the formulas you create. The following is the equivalent of the traditional formula presented earlier:

=IFERROR(B8/B9,0)

In this instance, the formula B8/B9 is evaluated and, if it results in an error, the 0 value is returned. If there is no error, then the value of the formula being evaluated is instead returned.

You can find additional information about the IFERROR function at this web page:

https://exceljet.net/excel-functions/excel-iferror-function

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7800) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Special Characters in Fields

If you try to add a quote mark or a backslash as part of a field parameter or switch, you may be surprised at what you ...

Discover More

Lines that Don't Change When You Type

Create a form in Word and you will invariably be faced with the need to places fill-in-the-blank lines in the document. ...

Discover More

Changing Number Display Settings for Single Workbooks

How Excel displays numbers is extremely flexible, but it can also be very confusing. This tip looks at how number display ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Selective Summing

If you want to add up the contents of a range of cells based on what is contained in a different range of cells, you need ...

Discover More

Pulling Initial Letters from a String

When working with names or a different series of words, you may need to pull the initial letters from each word in the ...

Discover More

Separating Names into Individual Columns

If you have a list of names in a column, and you want to separate those names into individual cells, there are several ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 4?

2017-10-13 10:46:26

Dave Bonin

I take a little different approach than the above. My philosophy is:
1) A user should never see a #DIV/0! or #NUM! or any other error simply because cells in a formula are empty, and
2) A user should never see a misleading value simply because not all cells in a formula have values yet.

Allen's sample formula uses two cells, B8 and B9. When calculating =B8/B9, wrapping an =IFERROR() function
around B8/B9 addresses only my first rule, but not my second.

Here's what I would routinely do:
= if( count( B8, B9 ) = 2, if( B9 <> 0, B8 / B9, "Some caution to the user that B9 is 0" ), "•" )

Breaking it down, I check that we have two numeric values in B8 and B9. If I do, then we can check whether B9 is zero.
If we don't, then I show a dot character Ctrl-0149.

Why that character? Because it's typically not used for anything else and it looks clean.

Why not a blank, such as ""? Because the dot character allows me to see that there is a formula in the cell. With a blank,
I can't tell unless I actually examine the formula in that individual cell.

To go one step further, I typically use conditional formatting (or sometimes numeric formatting with colors codes) to
make the dot a light gray color. I can see it's there, but it's not intrusive.

Q: So, why go through this extra work?
A: Defensive programming.

Much of my work is used by others, including upper management. This approach forestalls the questions I would otherwise
get when calculations are done with an incomplete set of operands.

In addition, it's been my observation that even one error message can lead users to believe a spreadsheet is faulty or buggy.
This helps prevent that wrong impression.



example,


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.