IFERROR function
The IFERROR function in Excel is used to handle errors in formulas and return a custom result when an error is encountered. It helps prevent error messages like #DIV/0!, #N/A, #VALUE!, and others from showing up in your spreadsheet, making your reports or calculations cleaner and easier to read.
Syntax:
IFERROR(value, value_if_error)
Arguments:
- value: The value or formula you want to check for errors.
- value_if_error: The value to return if the value results in an error. This could be a number, text, or another formula to handle the error.
Return Value:
- If the value does not result in an error, the IFERROR function returns the result of that value or formula.
- If the value results in an error, the function returns the value_if_error result.
Example:
Example 1: Handling division by zero
- Formula:
=IFERROR(A1/B1, "Error: Division by Zero") - Explanation: If B1 is zero (or empty), the formula will return
"Error: Division by Zero"instead of showing#DIV/0!. - Result:
- If A1 = 10 and B1 = 2, the result will be
5. - If A1 = 10 and B1 = 0, the result will be
"Error: Division by Zero".
- If A1 = 10 and B1 = 2, the result will be
Example 2: Handling #N/A errors in a lookup function
- Formula:
=IFERROR(VLOOKUP(C1, A2:B10, 2, FALSE), "Not Found") - Explanation: If the VLOOKUP function returns an error (e.g., if the value in C1 isn’t found in the lookup range A2:B10), the formula will return
"Not Found"instead of showing#N/A. - Result:
- If C1 matches a value in the lookup range, the corresponding value is returned.
- If no match is found,
"Not Found"is returned instead of#N/A.
Example 3: Using IFERROR with multiple functions
- Formula:
=IFERROR(SQRT(A1), 0) - Explanation: If the value in A1 is negative (which would result in an error when trying to find the square root), it returns
0instead of showing an error. - Result:
- If A1 = 16, the result will be
4. - If A1 = -16, the result will be
0instead of#NUM!.
- If A1 = 16, the result will be
Example 4: Suppressing error in formula results
- Formula:
=IFERROR(1/0, "Invalid Operation") - Result:
- Since
1/0results in a #DIV/0! error, the formula will return"Invalid Operation"instead of the error.
- Since
Key Points:
- Error Handling: IFERROR is useful when you expect errors in a formula (such as dividing by zero, looking up a non-existent value, or performing operations on invalid data) and want to display a more user-friendly message or an alternative value instead.
- Preventing Error Display: It helps keep your worksheet clean by preventing error messages like
#DIV/0!,#N/A,#VALUE!, and others from showing up, improving readability and user experience. - Use with Other Functions: It is commonly used with functions that might return errors, like
VLOOKUP,HLOOKUP,MATCH,INDEX,DIVIDE, and more. - Formula Efficiency: It eliminates the need for multiple nested IF or ISERROR functions, simplifying error handling in your formulas.
Use Cases:
- Cleaning up Lookup Formulas: Instead of displaying
#N/Awhen a lookup fails, you can use IFERROR to return a custom message:=IFERROR(VLOOKUP(D1, A1:B10, 2, FALSE), "Not Found") - Handling Mathematical Errors: Use IFERROR to handle division by zero or other math errors:
=IFERROR(A1/B1, 0) ' Returns 0 if B1 is 0 or empty - Custom Error Messages: Instead of showing generic error messages, you can return custom error messages, making it easier for users to understand what’s wrong:
=IFERROR(SUM(A1:A10)/SUM(B1:B10), "Error: Division Issue") - In Data Entry or Validation: If you’re performing data validation or checking, you can use IFERROR to cleanly handle situations where the data is missing or incorrect.