ShareYourGroupShareYourGroupGoogle Sheets

Logical

IFERROR and IFNA functions in Google Sheets

IFERROR returns a value of your choice when a formula gives an error; IFNA does so only for the #N/A error.

Some errors are not mistakes. A code that is not in the list, a month with no sales yet, an import still loading: each produces an error value where a calm blank or a short note would serve the reader better. IFERROR supplies that.

Syntax

=IFERROR(value, [value_if_error])
=IFNA(value, value_if_na)
ArgumentWhat it is
valueThe formula to try.
value_if_errorWhat to show if it gives an error. In Sheets this may be left out, and the result is then blank.

Examples

Sample sheet: A small price list with item codes. The table is sorted by code.
ABCDE
1CodeItemCategoryPriceStock
2A101Basmati Rice 5 kgGrocery65040
3A102Toor Dal 1 kgGrocery16075
4B201NotebookStationery60300
5B202Ball PenStationery100
6C301LED BulbElectronics110200
7C302Power BankElectronics129918
8D401Steel BottleHome45055

How it works

IFERROR works out its first argument. If the result is fine, that is what you see. If it is any error, you see the second argument instead.

In Google Sheets the second argument is optional. =IFERROR(formula) returns a blank on error, which is a short way to hide errors in a display column.

Where Sheets users need it most

It hides everything

IFERROR does not ask why the formula failed. A misspelt function name, a range that no longer exists and a column number beyond the table are all hidden as thoroughly as a missing code. The sheet looks tidy and is wrong.

The errors it covers:

ErrorUsual meaning
#N/Avalue not found
#DIV/0!division by zero
#VALUE!wrong kind of data
#REF!a reference that does not exist
#NAME?unknown function or name
#NUM!impossible number
#ERROR!the formula could not be read at all

Only the first two are normally expected.

Prefer IFNA for lookups

IFNA replaces #N/A only. A missing key gets your message. Any other error stays visible, so you find out about real faults. The last two examples show the difference.

Good habits

  1. Get the formula right without the wrapper first.
  2. Add IFERROR or IFNA last.
  3. Choose the replacement with care. A 0 flows into totals as if it were data. A blank or a word such as "Not found" does not.
  4. For division, test the cause directly: =IF(E5=0, "", D2/E5).

With ARRAYFORMULA

IFERROR works across a whole column: =ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, Prices!A:D, 4, FALSE))) leaves a blank on every row where the code is missing, including the empty rows at the bottom. That makes the usual IF(A2:A="", "", ...) guard unnecessary in this particular case.

Common mistakes

In Excel

IFERROR and IFNA exist in Excel. There, IFERROR's second argument is required.

Related functions

The results on this page were worked out by us from the sample sheet; they were not produced by a script running Google Sheets. If Sheets shows you something different, please tell us.

This is an independent help site. It is not connected with or approved by Google. Google Sheets is a trademark of Google LLC, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.