How to use the IFERROR function
The IFERROR function lets you catch most errors in Excel formulas. It was introduced in Excel 2007. In previous Excel versions, you could check for errors with the ISERROR function, it would return TRUE if the formula returned an error and FALSE if it was correct.
The IFERROR function makes it possible to create smaller formulas and still handle errors because the calculation is only needed once in the formula.
Table of Contents
- Syntax
- Arguments
- Example
- What errors doesn't the function catch?
- How to catch the #N/A Error?
- How to catch the #VALUE! error?
- How to catch the #REF Error?
- How to catch the #DIV/0 Error
- How to catch the #NUM Error
- How to catch the #NAME Error
- How to catch the #NULL Error
- How can I find all errors in a worksheet?
- IFERROR function simplifies finding errors in formulas
- Excel error functions
- Get Excel file
1. Syntax
IFERROR(value, value_if_error)
2. Arguments
value | A cell reference or a formula to check for errors. |
value_if_error | The value to return if the value argument evaluates to an error. The following error types are evaluated: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!. |
If the value argument returns an error, the value_if_error argument is used. If the value argument does NOT return an error, the IFERROR function returns the value argument.
3. Example
Formula in cell D3:
The formula returns "Error" if cell B3 evaluates an error. Column C shows what the corresponding cell contains in column B.
4. What errors doesn't the IFERROR function catch?
The IFERROR function catches most errors except the #SPILL error and VBA errors in macros or UDFs.
Be careful using the IFERROR function, it will make it a lot harder to find errors in your worksheet that otherwise would be easy to spot.
5. How to catch the #N/A Error?
The image above shows a formula in cell B3 that returns a #N/A meaning "Value not available" error. The IFERROR function catches this error, however, if you want to detect exactly a #N/A error use the ISNA function or the IFNA function.
Formula in cell B2:
This error is returned if a value is not found using one of these functions: MATCH, VLOOKUP, LOOKUP, HLOOKUP and XLOOKUP etc. The MATCH function looks for an exact match using 0 (zero) as the lookup value and 1 as the lookup array, it can't find the value and returns "#N/A".
The formula in cell C2 returns "error" if the value argument returns an error, in this case, it does.
Formula in cell C2:
You can also reference a formula in another cell using the IFERROR function, this is demonstrated in cell D2.
Formula in cell D2:
Cell B2 returns "#N/A" error and that makes the formula in cell D2 return "Error".
How to correct a #N/A error? The function you are using can't find the value you are looking for, try another lookup value or check that you reference the correct lookup array.
6. How to catch the #VALUE! error?
The image above demonstrates a formula in cell B3 that returns the #VALUE! error. The formula tries to multiply a text string with a number, this mathematical operation is not valid.
Formula in cell B3:
How to correct the #VALUE! error? You have made a mistake when you built the function using arguments or one or more arguments are trying to do something that is not valid. For example. you perhaps are using text strings when the function only accepts numerical values.
Formula in cell C3:
The IFERROR function catches the #VALUE! error as well, cell C3 returns "Error".
The Formula in cell D3 references cell B3 and returns "Error" because cell B3 evaluates to an error.
7. How to catch the #REF Error?
The IFERROR function is able to catch #REF! errors, as well. The #REF! error is returned when you use an invalid cell reference.
Formula in cell B4:
The OFFSET function above tries to return a value from the row above cell A1 which is not possible. Excel returns a #REF! error.
Formula in cell C4:
How to correct the #REF! error? Often a cell reference is not valid, possibly been deleted or pointing to an incorrect location.
Formula in cell D4:
The ISREF function checks if a value is a cell reference.
8. How to catch the #DIV/0 Error
The image above shows a formula in cell B3 that returns #DIV/0! error, this happens a formula tries to divide a number with 0 (zero).
Dividing a number with zero is not possible: Division by zero (wikipedia)
Formula in cell B5:
The formula in cell B5 tries to divide 1 with 0 (zero), Excel returns the #DIV/0! error. How to correct a #DIV/0! error? Make sure that the divisor is not 0 (zero).
dividend/divisor = quotient
Formula in cell C5:
Formula in cell D5:
9. How to catch the #NUM Error
The image above shows a formula in cell B3 that returns a #NUM! error. You get this result when you use an invalid number.
Formula in cell B7:
The formula in cell B7 returns #NUM! error, the second argument is a negative number which is not allowed. You can only positive numbers in this argument.
How to correct a #NUM! error? Check your function arguments carefully.
Formula in cell C7:
Formula in cell D7:
10. How to catch the #NAME Error
The image above demonstrates a formula in cell B3 that returns #NAME! error.
Formula in cell B8:
The formula above tries to concatenate Text with 1 which is not possible.
How to correct a #NAME! error? There are many things that can be wrong here.
- Misspelled a named range.
- Misspelled a User Defined Function.
- Forgot to use double quotes before and after a text string.
Formula in cell C8:
Formula in cell D8:
11. How to catch the #NULL Error
You get the #NULL! error if you use an invalid cell reference in a formula or if you calculate the intersection of two cell ranges, however, they don't intersect.
Formula in cell B9:
This formula calculates the intersection of two cell references using the space character. It returns a #NULL! error because they don't intersect meaning they don't cross or overlap.
How to correct a #NULL! error? Check your cell references and make sure that intersecting cell ranges cross each other.
Formula in cell C9:
Formula in cell D9:
12. How can I find all errors in a worksheet?
Use the "Find & Replace" tool which is built-in to Excel, press short cut keys CTRL + F to launch it. A dialog box appears, enter the value you want to look for, in this example, #VALUE!
Press with left mouse button on "Options" button to see all settings. Change "Look in:" to Values, this is important or you won't find anything in your worksheet.
This method will, however, not catch errors inside the IFERROR function. As far as I know, you can't find those errors. I recommend that you use this method to locate all formulas using the IFERROR function and then, one by one, use the "Evaluate Formulas" tool to spot errors.
- Select the cell containing the IFERROR function.
- Go to tab "Formulas" on the ribbon.
- Press with left mouse button on the "Evaluate Formulas" button.
- Keep press with left mouse button oning the "Evaluate" button until you spot the error.
- Press with left mouse button on "Close" button to dismiss the dialog box.
- Repeat with the next cell.
13. IFERROR function simplifies formulas
Example 1
In previous Excel versions you could check for errors using the ISERROR function. This example shows both functions, the ISERROR function in cell C10 and IFERROR function in C12. The formula in cell C12 is much smaller.
Formula in cell C10:
Formula in cell C13:
Example 2
Here the price is missing for product A. The IFERROR function simplifies the formula in cell C13.
Formula in cell C10:
Formula in cell C13:
13.1 Explaining the formula in cell C12
Step 1 - Find a value and return corresponding value
INDEX(C3:C7,MATCH(C12,B3:B7,0))
becomes
INDEX(C3:C7,MATCH("A",{"A";"B";"C";"D";"E"},0))
becomes
INDEX(C3:C7, 1)
becomes
INDEX({0;2;4;2;3}, 1)
Step 2 - Divide 1 with the returned value
=IFERROR(1/(1/(INDEX(C3:C7,MATCH(C12,B3:B7,0)))),"Insert new price")
becomes
=IFERROR(1/(1/0)),"Insert new price")
becomes
=IFERROR(1/#DIV/0),"Insert new price")
becomes
=IFERROR(#DIV/0,"Insert new price")
and returns "Insert new price" in cell C13.
14. Function not working
The IFERROR function returns
- #NAME? error if you misspell the function name.
- #SPILL error happens if the destination or spill range is not empty.
It does not propagate errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
14.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
14.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3:B4 converted to hard-coded value using the F9 key. The IFERROR function requires an empty spill range which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
14.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Back to top
'IFERROR' function examples
First, let me explain the difference between unique values and unique distinct values, it is important you know the difference […]
This post explains how to lookup a value and return multiple values. No array formula required.
This blog article describes how to split strings in a cell with space as a delimiting character, like Text to […]
Functions in 'Logical' category
The IFERROR function function is one of 16 functions in the 'Logical' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form