Safe division
| A | B | |
|---|---|---|
| 1 | Revenue | Units |
| 2 | 10 | 0 |
Formula: D2: =IFERROR(A2/B2,0)
Result: 0
Dividing by zero gives #DIV/0!, which IFERROR replaces with 0.
Replaces any error.
IFERROR(value, value_if_error)Example: =IFERROR(B2/C2,0)
Available in: All versions
IFERROR returns a replacement value when a formula produces any error, and the formula result otherwise: =IFERROR(value, value_if_error). It is the quickest way to hide #N/A, #DIV/0! and similar errors in reports.
| A | B | |
|---|---|---|
| 1 | Revenue | Units |
| 2 | 10 | 0 |
Formula: D2: =IFERROR(A2/B2,0)
Result: 0
Dividing by zero gives #DIV/0!, which IFERROR replaces with 0.
| A | B | |
|---|---|---|
| 1 | SKU | Price |
| 2 | A101 | 24.99 |
| 3 | A102 | 39 |
Formula: D2: =IFERROR(VLOOKUP("Z9",A2:B3,2,FALSE),"Not found")
Result: Not found
Z9 is not in the list, so VLOOKUP returns #N/A and IFERROR shows the text.
| A | |
|---|---|
| 1 | Notes |
| 2 | n/a |
| 3 | pending |
Formula: D1: =IFERROR(AVERAGE(B2:B4),"No data")
Result: No data
AVERAGE of cells with no numbers gives #DIV/0!, replaced by "No data".
A tiny spreadsheet with example data. Edit the formula or any number and see the result.
Formula in F2: =IFERROR(B3/D3,"n/a")
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Extra credit | Attempts | Result | |
| 2 | Ann | 92 | Yes | 2 | n/a | |
| 3 | Bob | 74 | No | 0 | ||
| 4 | Cy | 58 | Yes | 3 | ||
| 5 | Dee | 81 | No | 1 | ||
| 6 | Eli | 66 | 2 |
Enter — commit · F2 — edit · F4 — $ in a reference · Ctrl+C/Ctrl+V — copy and paste · Ctrl+Z — undo
Esc or F6 — leave the sheet for the «Check» button · Shift+Tab in the first cell — back to the page