Sub topic 1
What Excel error values tell you
When a formula cannot produce a result, Excel stores an error value in the cell instead. Each error value names the kind of failure. Before you hide errors with IFERROR or IFNA, you need to be able to read them. A formula that hides the wrong error can make a broken workbook look healthy.
Prerequisites
This chapter assumes you can do the following:
- Enter a formula and copy it down a column.
- Tell relative references (
A2) from absolute references ($A$2). - Use IF and a basic lookup such as VLOOKUP.
No other functions are needed. Every function used here is explained when it first appears.
Error values are values, not messages
An error value is a real result stored in a cell, in the same way 42 or "Smith" is. It is not a pop-up or a warning that sits on top of the sheet. Three consequences follow:
- Other formulas can read an error value, test it, and pass it along.
- An error is not text. The cell holds the error itself, not the characters
#N/A. - A cell that shows an error has a result. It is not empty and it is not zero.
The built-in error values are these:
| Error | Short meaning |
|---|---|
| `#DIV/0!` | A division by zero, or by an empty cell |
| `#N/A` | A value is not available, most often a lookup that found no match |
| `#VALUE!` | An argument or operand is the wrong type |
| `#REF!` | A reference points to a cell that no longer exists |
| `#NAME?` | Excel does not recognize a function name, range name, or text |
| `#NUM!` | A number is invalid or too large or small for the calculation |
| `#NULL!` | Two ranges were given an intersection that does not exist |
Current versions of Excel add a few more, such as #SPILL! (a dynamic array has no room to expand) and #CALC! (a calculation engine problem, such as an empty array). The next chapter covers the causes of the seven classic errors in detail. Here the goal is to understand how errors behave.
A worked example
Suppose you track revenue per unit sold:
| Row | A | B | C |
|---|---|---|---|
| 1 | Revenue | Units | Per unit |
| 2 | 500 | 10 | |
| 3 | 300 | 0 | |
| 4 | 450 | 9 | |
| 5 | 200 |
Enter this in C2 and copy it down to C5:
=A2/B2The results are:
C2shows50.C3shows#DIV/0!, becauseB3is0.C4shows50.C5shows#DIV/0!, because an empty cell counts as zero in arithmetic.
The error is not limited to the cell where it starts. Add a total in C7:
=SUM(C2:C5)C7 also shows #DIV/0!. SUM does not skip the bad cells. It receives an error as one of its inputs and returns that error.
Errors propagate
Propagation means that when a formula reads a cell containing an error, the formula usually returns the same error. Most functions and operators work this way:
=C3*2
=C3+C4
=ROUND(C3, 1)
=AVERAGE(C2:C5)All four formulas return #DIV/0!, because each one depends on C3. A single bad cell can spread through a chain of formulas into a summary far from the source. You may see #DIV/0! in a dashboard total while the real problem is one empty cell on a data sheet.
When you meet an error in a result, find the first cell in the chain that has the error. That cell is the source. Every cell after it is only repeating the error.
Some functions do not propagate
A few functions are built to cope with errors in their inputs. The most useful for totals is AGGREGATE, which has an option to ignore error values:
=AGGREGATE(9, 6, C2:C5)Here 9 selects SUM and 6 means "ignore error values". The result is 100, the sum of the two valid cells. The error cells are still there, but the total no longer fails.
IFERROR and IFNA, the subject of the later chapters, are the other main tools. They sit between the failing cell and everything that depends on it.
Reading an error as a diagnosis
Each error is a diagnosis with limited detail. It tells you which category of problem occurred, not which cell is at fault. Use the error to narrow your search:
#DIV/0!means a divisor is zero or blank. Look at the denominator.#N/Ameans something was not found. Look at the lookup value and the lookup range.#VALUE!means a type mismatch. Look for text where a number is expected.#REF!means a deleted or invalid reference. Look for a deleted row, column, or sheet.#NAME?means a name was not recognized. Look for a typo in a function or range name.#NUM!means an invalid number. Look at arguments such as the square root of a negative number.#NULL!means a bad range operator. Look for a space or a missing comma or colon between references.
#N/A deserves special attention. It is the only error that often means "no match, which may be perfectly normal". A lookup that fails to find an item can be a legitimate answer. The other errors usually point to a mistake in the formula or the data. This difference is why IFNA exists as a narrower tool than IFERROR.
Excel's tools for finding the source
You do not have to trace errors by eye. These features are on the Formulas tab:
- Error Checking steps through errors in the sheet and offers an explanation for each.
- Trace Precedents draws arrows from the cells a formula reads. Use it on a cell with an error to find which input is the first bad one.
- Evaluate Formula shows a formula one step at a time, so you can see which sub-expression fails.
A small green triangle in a cell corner is a warning from background error checking. It can flag a formula that is inconsistent with its neighbors, or one that omits adjacent cells. It is not an error value, and the cell can still show a perfectly good number.
The tools also work on formulas from other people. If you inherit a workbook with hundreds of IFERROR wrappers, trace precedents and evaluate the formula with the wrapper removed. The wrapper hides the very information you need.
Testing for errors in a formula
Because errors are values, a formula can test for them. Excel provides these functions, each of which returns TRUE or FALSE:
| Function | TRUE when the value is |
|---|---|
| `ISERROR(value)` | Any error value |
| `ISERR(value)` | Any error except `#N/A` |
| `ISNA(value)` | Exactly `#N/A` |
Combine them with IF to branch on the result:
=IF(ISERROR(C3), "Check units", C3)If C3 is any error, the cell shows Check units. Otherwise it shows the number. Calling ISNA on C3 would return FALSE here, because #DIV/0! is not #N/A.
This pattern evaluates the cell twice and is wordy. IFERROR and IFNA replace it with a shorter form, which the next chapters cover.
Identifying which error occurred
ERROR.TYPE returns a number that identifies the error:
=ERROR.TYPE(C3)For #DIV/0!, this returns 2. The numbers for the classic errors are:
| Number | Error |
|---|---|
| 1 | `#NULL!` |
| 2 | `#DIV/0!` |
| 3 | `#VALUE!` |
| 4 | `#REF!` |
| 5 | `#NAME?` |
| 6 | `#NUM!` |
| 7 | `#N/A` |
If the cell does not contain an error, ERROR.TYPE itself returns #N/A. That behavior surprises many people. Wrap it in a test first, or use it only on cells you already know are errors.
A diagnostic column is a good way to audit a sheet. Put the following next to a suspect column and filter on the results:
=IF(ISERROR(C2), ERROR.TYPE(C2), "")You get a number for each error cell and a blank otherwise. Filtering shows you which categories of error you have and how many.
Errors you create on purpose
Sometimes an error is the correct output. The NA function returns #N/A deliberately:
=IF(B2="", NA(), A2/B2)This is common when preparing data for a chart. Excel line charts skip #N/A points instead of plotting them as zero, so a gap in the data appears as a gap in the line. If you replaced that #N/A with 0, the chart would drop to zero, which would be wrong.
A callout is worth keeping in mind here:
Why errors are worth keeping visible
An error value is a loud failure. It stops totals from showing misleading numbers. A sum that ignores a failed division would look correct but understate revenue. Errors force a decision.
Handling functions turn a loud failure into a quiet one. That is the right trade in some cases, such as a lookup where "not found" is a normal outcome. It is the wrong trade when the formula has a real defect. The later chapters return to this idea, called the masking risk. For now, keep this rule: do not hide an error until you know what caused it and have decided that hiding it is correct.
Common mistakes when reading errors
- Treating the last error as the cause. The first failing cell in the chain is the cause. Cells after it only repeat the error.
- Confusing
#####with an error. Hash marks filling a cell mean the column is too narrow for the number or date. Widen the column. No error value is stored. - Assuming a blank cell is not zero. In arithmetic, an empty cell counts as
0, which is how empty cells cause#DIV/0!. - Expecting ERROR.TYPE to work on any cell. It returns
#N/Afor a cell with no error. - Fixing the symptom at the total. Handling errors in the total hides the problem and leaves bad data upstream.
Summary
Error values are real results that propagate through dependent formulas. Each names a category of failure, and #N/A is the one that often represents a normal outcome such as a missing match. You can test for errors with ISERROR, ISERR, and ISNA, and identify them with ERROR.TYPE. The next chapter covers the causes of each classic error in more detail.
Exercise
Cell C3 contains =A3/B3 and shows #DIV/0!. Cell C7 contains =SUM(C2:C5) and also shows #DIV/0!. Which cell is the source of the error, and how could you total the valid values in C2:C5 without changing C3?
Show answer
C3 is the source, because its divisor B3 is zero or empty. C7 only repeats the error that SUM receives from C3. To total the valid cells without changing C3, use =AGGREGATE(9, 6, C2:C5). Option 6 tells AGGREGATE to ignore error values.
Exercise
What does each formula return when A1 contains #N/A: =ISERROR(A1), =ISERR(A1), =ISNA(A1), and =ERROR.TYPE(A1)?
Show answer
=ISERROR(A1) returns TRUE because #N/A is an error. =ISERR(A1) returns FALSE because ISERR excludes #N/A. =ISNA(A1) returns TRUE. =ERROR.TYPE(A1) returns 7, the number for #N/A.
Exercise
You are building a line chart from column C, and some months have no data. Why might =IF(B2="", NA(), A2/B2) be better than =IF(B2="", 0, A2/B2)?
Show answer
Excel line charts skip #N/A points, so a month with no data leaves a gap in the line. A 0 would be plotted as a real value, and the line would drop to zero, which misrepresents the data.