Logical
Catching an error from a divide
Definition
Guarding a divide so an error becomes a fallback value means wrapping the divide in IFERROR.
Syntax
=IFERROR(value, value_if_error)
Arguments
| Argument | Meaning |
|---|---|
value |
The divide to try, for example B2/C2. |
value_if_error |
The fallback to show when the divide fails, such as 0. |
Worked example
A mix sheet divides grams in B2 by portions in C2 and uses 0 when the divide cannot run.
| A: Mix | B: Grams | C: Portions |
|---|---|---|
| A | 20 | 4 |
| B | 15 | 0 |
| C | 9 | 3 |
Formula: =IFERROR(B2/C2,0)
Result: 5. 20 divided by 4 is 5, so the fallback is unused.
Practice
Cell C2 holds 8. Cell D2 holds 0. In E2, write a formula that divides C2 by D2 and shows -1 when that divide fails.
- In E2, write an IFERROR formula that divides C2 by D2 and shows -1 on error.
- E2 should show C2 divided by D2, or -1 on error.
Step 1 of 2
Enter =IFERROR(C2/D2,-1) in E2.
D2 is 0, so C2 divided by D2 is an error and the result is -1.
Formulas here use English function names, such as SUM, and a period as the decimal separator, in every language.
Loading the sheet…
E2 uses IFERROR.
E2 now shows -1.
The next lesson is Reading the day of the month.
Related functions
IFERROR is the function that swaps an error from the divide for the fallback value.
Common mistake
Putting the fallback first, as in =IFERROR(0,B2/C2): the cell then always shows 0 and never returns 5.