- value - The value, reference, or formula to check for an error.
- value_if_error - The value to return if an error is found.
How to use
The IFERROR function is used to catch errors and return a more friendly result or message when an error is detected. When a formula returns a normal result, the IFERROR function returns that result. When a formula returns an error, IFERROR returns an alternative result. IFERROR is an elegant way to trap and manage errors. The IFERROR function is a modern alternative to the ISERROR function.
Use the IFERROR function to trap and handle errors produced by other formulas or functions. IFERROR checks for the following errors: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.
In the example shown, the formula in E5 copied down is:
This formula catches the #DIV/0! error that occurs when Qty is empty or zero, and replaces it with zero.
For example, if A1 contains 10, B1 is blank, and C1 contains the formula =A1/B1, the following formula will catch the #DIV/0! error that results from dividing A1 by B1:
=IFERROR (A1/B1,"Please enter a value in B1")
As long as B1 is empty, C1 will display the message "Please enter a value in B1" if B1 is blank or zero. When a number is entered in B1, the formula will return the result of A1/B1.
You can also use the IFERROR function to catch the #N/A error VLOOKUP throws when a lookup value isn't found. The syntax looks like this:
In this example, the IFERROR function evaluates the result returned by VLOOKUP. If no error is present, the result is returned unchanged. However, if VLOOKUP returns an #N/A error, IFERROR catches the error and returns "Not Found".
IFERROR or IFNA?
The IFERROR function is a useful function, but it is a rather blunt instrument that will trap all kinds of errors. For example, if a function is misspelled in a formula, Excel will return the #NAME? error and IFERROR will catch that error too, and return an alternate result. This can cause IFERROR to hide an important problem. In most cases, it makes more sense to use the IFNA function with VLOOKUP instead of IFERROR.
Unlike IFERROR, IFNA only traps the #N/A error.
Other error functions
Excel provides a number of error-related functions, each with a different behavior:
- The ISERR function returns TRUE for any error type except the #N/A error.
- The ISERROR function returns TRUE for any error.
- The ISNA function returns TRUE for #N/A errors only.
- The ERROR.TYPE function returns the numeric code for a given error.
- The IFERROR function traps errors and provides an alternative result.
- The IFNA function traps #N/A errors and provides an alternative result.
- If value is empty, it is evaluated as an empty string ("") and not an error.
- If value_if_error is supplied as an empty string (""), no message is displayed when an error is detected.
- In Excel 2013+, you can use the IFNA function to trap and handle #N/A errors specifically.