Prevent Errors From Appearing in Excel

Add to Favorites
Author: | Edits: don

How to prevent errors from appearing in formulas in Excel. This is especially helpful for the Vlookup function.

Sections:

Excel 2007 and Later

Excel 2003 and Earlier

Notes

Excel 2007 and Later

This is very easy to do in Excel 2007 and later using the IFERROR() function.

Syntax

=IFERROR(value, value_if_error)

The value is the function or formula that you would normally put into the cell and the value_if_error argument is the output that you want to appear when there would otherwise be an error output.

Example

=IFERROR(1/0,"Custom Error Output")

Here, I am trying to divide 1 by 0, which is impossible and which will return an error.

If I put this formula into a cell without IFERROR it will look like this:

895d13e95c0815ae481d87c5c6eccf79.png

Note that you do need the equal sign when putting a formula into a cell but you do not need it when putting it into the IFERROR function.

The result is this:

4327274d2376b41e6b6916c5578f149d.png

In cell A1, you can see the nice custom error message from the IFERROR function and in cell A2, you can see the original nasty error message.

Using IFERROR, you can output whatever you want when there is an error. You simply fill-out the value_if_error argument in one of the following ways:

Output Text

Put text surrounded by double quotation marks like in the example above.

Output a Blank

Put double quotation marks with nothing between them.

Output a 0

Type a 0 or leave the argument blank.

Output a Number

Type the desired number.

Don't forget that for the first argument (value) you can input any formula or function that you want. I kept the example here simple so you wouldn't focus on the formula that caused the error. However, this setup is perfect for the VLOOKUP function, which returns an error when the lookup_value argument is empty.

Excel 2003 and Earlier

There is no IFERROR function in Excel 2003 and earlier. We need to use the IF function combined with the ISERROR function.

=IF(ISERROR(1/0),"Custom Error Output",1/0)

fdb9fab2abe41d085c9b4f146f158b57.png

I am using 1/0 for the formula that will cause an error because it is simple and throws an error.

Here, you can see that the ISERROR function is put inside the IF function and that we have to write the formula that causes, or might cause, an error twice. When you are working with really long formulas, this can be a real annoyance, but it is the only way to hide default error output in Excel 2003 and have your own custom error message for formulas.

I used 1/0 for the error causing formula but you can use whatever formula or function you need. Simply wrap that formula/function within the IF and ISERROR functions like in the example above; remember that you will have to put it twice and that you do not put the equals sign in front of it since we are nesting it within a formula.

Just like the example for Excel 2007 and later, you can output a variety of different things, be that text, numbers, 0, or a blank. Just replace "Custom Error Output" from the above formula with one of these options:

Output Text

Put text surrounded by double quotation marks like in the example above.

Output a Blank

Put double quotation marks with nothing between them.

Output a 0

Type a 0 or leave the argument blank.

Output a Number

Type the desired number.

Notes

Preventing errors from appearing in Excel was made much easier starting with Excel 2007. It can be done in Excel 2003, but it can be very difficult to maintain when you have a long and complex formula for which you don't want an error to display. That said, you now know how to suppress and customize error message for formulas and functions in Excel, regardless of the version of Excel that you use.

Make sure to download the sample spreadsheet attached to this tutorial to work with this in Excel.


Excel Function: IF(), IFERROR(), ISERROR()
Downloadable Files: Excel File

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Prevent Charts from Printing in Excel
Tutorial: This is how you prevent a chart from appearing when you print from Excel. This is a gre...
Get Text from Comments in Excel Including the Author of the Comment - UDF
Macro: Output all text from a cell comment, including comment author, with this UDF in Excel. Thi...
Remove All HTML from Text in Excel
Tutorial: How to quickly and easily remove all HTML from data copied into Excel. This tutorial inclu...
Display The Actual Link / Email Address From Links in Excel - UDF
Macro: Display the actual link or email address from links within Excel with this UDF. This user ...
3 Methods to Remove Spaces Between Text in Excel
Tutorial: How to remove spaces from the middle of text in Excel.  This includes removing all space...
How to Create and Manage a Chart in Excel
Tutorial: In this tutorial I am going to introduce you to creating and managing charts in Excel. Bef...
Tutorial Details
Excel Function: IF(), IFERROR(), ISERROR()
Downloadable Files: Excel File
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course