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.

  1. In E2, write an IFERROR formula that divides C2 by D2 and shows -1 on error.
Step 1 of 2
Formulas here use English function names, such as SUM, and a period as the decimal separator, in every language.
Loading the sheet…

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.

Related functions

These links are related functions.