Sub topic 11
Common errors and handling them with IFERROR
Aggregate formulas usually work as soon as their ranges contain suitable data. Errors appear when the range, arguments, or source data do not match what the function expects. Learning to identify the error first is better than immediately hiding it.
The most common errors
AVERAGE returns #DIV/0! when its range contains no numeric values. The function calculates a total divided by the number of numbers. If that count is zero, the division is impossible.
=AVERAGE(B2:B6)If B2:B6 contains only text and blank cells, use IFERROR to show a useful message:
=IFERROR(AVERAGE(B2:B6), "No data")IFERROR is a function that returns its first argument when that argument works. If the first argument produces an error, it returns the second argument instead. The second argument can be text, a number, or another formula.
| Formula | Result when B2:B6 has no numbers |
|---|---|
| `=AVERAGE(B2:B6)` | `#DIV/0!` |
| `=IFERROR(AVERAGE(B2:B6), "No data")` | `No data` |
| `=IFERROR(AVERAGE(B2:B6), 0)` | `0` |
#VALUE! often means that a formula received the wrong type of input. For example, a formula may expect a number but receive text from another calculation.
#REF! means that a formula refers to a cell or range that no longer exists. This can happen after deleting a referenced column or row. IFERROR can hide this error, but repairing the reference is usually safer.
#N/A commonly means that a lookup or another formula could not find a result. It is less common in a basic SUM or AVERAGE formula, but one error inside a referenced calculation can affect an aggregate.
Diagnose before hiding an error
Use this sequence:
- Read the error label.
- Check the referenced cells and ranges.
- Confirm that numbers are really stored as numbers.
- Check for deleted rows, columns, or invalid references.
- Add
IFERRORonly when a replacement result makes sense.
A zero is not always an appropriate replacement. 0 means that the result is numerically zero. It does not necessarily mean that data was missing. A message such as "No data" preserves that difference.
The following diagram shows the decision:
Use IFERROR with care
A formula such as this is convenient for a report:
=IFERROR(ROUND(AVERAGE(B2:B6), 2), "No data")The inner AVERAGE calculates the mean. ROUND limits the displayed result to two decimal places. IFERROR handles a missing-data error from either function.
However, IFERROR catches every error, not only #DIV/0!. If a range was accidentally deleted and the formula now has #REF!, the message "No data" could hide the real problem. During setup and troubleshooting, leave the original formula visible. Add error handling after you understand the expected cases.
Exercise
B2:B6 contains only blank cells and labels. Write a formula that returns the average rounded to two decimal places, but displays "No numeric data" instead of an error.
Show answer
=IFERROR(ROUND(AVERAGE(B2:B6), 2), "No numeric data")