We often use Excel formulas in our work life, and we may encounter this situation that the formula throws an error and finally an error like #DIV/0! Is displayed in the cell. In today’s tutorial, we will introduce you the application of Excel IFERROR function to catch errors and replace errors by specific values per your requirement.
In today’s example, if the IFERROR formula returns a normal value, we keep the normal value, and if it throws an error, we will return a specific value or a text to mark the error type.
Using a simple division as an example, the division reports error #DIV/0! if the divisor is zero. We use the following example to show you how to use Excel IFERROR function to return a specific value in Excel worksheet if #DIV/0! error is detected.
In this example, if the cell in Piece Count column is not empty, the formula will return the unit price calculated by Total/Piece; And if the cell in Piece Count column is empty, the formula will return the value saved in Total column instead.
In order to get the return value with $, we need to set the cell format to “Currency” before entering the formula. You can set “Currency” via Home->Number->Number Format dropdown list.
In this example, we have used only the IFERROR function without nesting other functions.
Excel IFERROR function detects if a formula or expression is in error and returns a specific value if the formula evaluates to an error. It returns the result of the formula or expression if there is no error.
In this example, we can directly apply this function with entering our own value and value if error.
= IFERROR(B2/C2, B2)
Normally, if we just enter =B2/C2 without applying Excel IFERROR function in unit price column, #DIV/0! error will be displayed if piece count is empty.
After introducing Excel IFERROR function, we can know that if error is thrown by the input expression or formula, we can record the error by setting a specific value (argument “value_if_error”) in IFERROR, then the normal error will be replaced by this value. This value can be a cell reference, a fixed value, a formula, or an error mark like “error code1”.
RETURN A SPECIFIC VALUE
In this example, we want to get the unit price by Total/Piece Count. We notice that in Piece Count column, some cells are empty, which means that the divisor is empty. In this case, we want to keep their total value as their unit price, so if we encounter an error like this, the total value will be returned by IFERROR.
Calculate B2/C2 in the formula bar:
Expression B2/C2 returns value 333.3333 and doesn’t throw an error, so the result of the expression is displayed in D2.
Calculate B4/C4 in the formula bar:
This time expression B4/C4 returns an error #DIV/0!, IFERROR detects this error and comes to value_if_error, we set value_if_error to B4, so value 3000 in B4 is returned by this formula.
RETURN A TEXT
We can replace error value with some other values. For example, we can enter text “ERROR” in the formula, if error is detected by Excel IFERROR function, “ERROR” is recorded in unit price column.
The formula is:
If text is entered in a formula, the entered text must be enclosed in double quotation marks. Otherwise, an error #NAME? will be thrown.
Excel IFERROR function
The Excel IFERROR function returns an alternate value you specify if a formula results in an error, or returns the result of the formula.The syntax of the IFERROR function is as below:= IFERROR (value, value_if_error)….