Sub topic 2
Handling Errors with IF, IFERROR and IFNA
Assume you know how to enter formulas, use cell references and ranges, and use functions such as SUM, AVERAGE, and VLOOKUP. An error-handling formula should address a known condition. It should not hide every mistake.
Handling errors with IF, IFERROR and IFNA
IF tests a condition and chooses one result when it is true and another when it is false. Check the divisor before dividing:
=IF(B2=0,"",A2/B2)This returns a blank when B2 is zero or empty. Otherwise, it performs the division.
IFERROR replaces any error produced by a formula:
=IFERROR(AVERAGE(B2:B10),"No data")Use it when several expected problems have the same user-facing result. IFNA is narrower. It replaces only #N/A, which commonly means that a lookup found no match:
=IFNA(VLOOKUP(E2,A2:B100,2,FALSE),"Not found")This keeps errors such as #REF! visible, so they can be repaired.
| Function | Handles | Good use |
|---|---|---|
| `IF` | A condition you specify | Preventing division by zero |
| `IFERROR` | Any formula error | Displaying a safe result for known input problems |
| `IFNA` | Only `#N/A` | Handling a missing lookup result |
Fixing #REF!: deleted or invalid references
#REF! means a formula points to a reference that no longer exists. This often happens after deleting a referenced row or column. Restore the deleted cells if possible, or edit the formula and replace #REF! with the correct range. Check lookup column indexes too. In VLOOKUP(E2,A2:B100,3,FALSE), index 3 is invalid because the table has only two columns.
Fixing #NAME?: misspelled names and functions
#NAME? means Excel does not recognize text in the formula. Check function spelling, defined names, and text criteria. For example, =SUMM(A1:A5) should be =SUM(A1:A5). Text values must also be inside quotation marks.
Fixing #N/A: lookups that find nothing
#N/A means a lookup did not find a matching value. Check spelling, spaces, data types, and whether the lookup range contains the key. Use IFNA for a valid “not found” case, but correct the source data when a match was expected.
Exercise
Which function should replace only a missing lookup result without hiding a #REF! error?
Show answer
IFNA, such as =IFNA(VLOOKUP(E2,A2:B100,2,FALSE),"Not found").