IFERROR Formula in Excel, VBA, and Google Sheets

This tutorial demonstrates how to use the Excel IFERROR Function to catch formula errors, replacing them with another formula, blank value, 0, or a custom message.

iferror function excel

IFERROR Function Overview

The IFERROR Function Checks if a formula results in an error. If FALSE, return the original result of the formula. If TRUE, return another specified value.


To use the IFERROR Excel Worksheet Function, select a cell and type:
Notice how the IFERROR formula inputs appear:
iferror formula syntax

AutoMacro - VBA Code Generator

IFERROR Function Syntax and Inputs:

value – An expression. Example: 4/A1

value_if_error – Value or Calculation to perform if the previous input results in an error. Example 0 or “” (blank)

What Is the IFERROR Function?

The IFERROR function falls under the category of Logical Functions in Microsoft Excel, which includes ISNA, ISERROR and ISERR. All of these functions help detect and handle formula errors.

IFERROR allows you to perform a calculation. If the calculation does not result in an error, then the calculation result is displayed. If the calculation does result in an error then another calculation is performed (or a static value like 0, blank, or some text is outputted).

When would you use the IFERROR Function?

  • When dividing numbers to avoid errors caused by dividing by 0
  • When performing lookups to prevent errors if the value isn’t found.
  • When you want to perform another calculation if the first results in an error (ex. Lookup a value in a 2nd table if it’s not found in the first table)

Un-handled formula errors can cause errors within your workbook, but visible errors also make your spreadsheet less visibly appealing.

If Error Then 0

Let’s look at a basic example. Below you are dividing two numbers.  If you attempt to divide by zero you will receive an error:

iferror function error

Instead, insert the calculation within the IFERROR function and if you divide by zero a 0 is outputted instead of an error:

excel iferror then 0

If Error Then Blank

Instead of setting errors to 0, you can set them to ‘blank’ with double quotations (“”):

iferror then blank

We will look at more IFERROR usages with the VLOOKUP function…


Lookup functions like VLOOKUP will generate errors if the lookup value is not found. As shown above, you can use the IFERROR Function to replace errors with blanks (“”) or 0s:

iferror vlookup zero

If Error Then Do Something Else

The IFERROR Function can also be used to perform a 2nd calculation if the 1st calculation results in an error:

Here if the data is not found in ‘LookupTable1’ a VLOOKUP is performed on ‘LookupTable2’ instead.

More IFERROR Formula Examples

Nested IFERROR – VLOOKUP Multiple Sheets

You can nest an IFERROR inside another IFERROR to perform 3 separate calculations. Here we will use two IFERRORs to perform VLOOKUPs on 3 separate worksheets:

iferror nested vlookup multiple sheets

Index / Match & XLOOKUP

Of course, IFERROR will also work with Index / Match and XLOOKUP formulas as well.


The XLOOKUP function is an advanced version of the VLOOKUP function.

iferror vlookup


INDEX and MATCH can be used to create more powerful VLOOKUPs (similar to how the new XLOOKUP function works) in Excel.

iferror index match

IFERROR in Arrays

Array formulas in Excel are used to perform several calculations through a single formula. Let’s suppose there are three columns of Year, Sales, and Avg Price. You can find out the total quantity with the following formula in the E column.

iferror array formula

The formula performs well until it attempts to divde by zero, resulting in the #DIV/0! error.

You can use the IFERROR function like this to resolve the error:

iferror array function excel

Notice that the IFERROR function must be nested inside the SUM Function, otherwise the IFERROR will apply to the sum total and not each individual item in the array.


The IFNA Function works exactly the same as the IFERROR Function except the IFNA function will only catch #N/A errors. This is extremely useful when working with lookup functions: regular formula errors will still be detected, but no error will appear if the lookup value is not found.

ifna function excel


If you are still using Microsoft Excel 2003 or an older version, then you can substitute IFERROR with a combination of IF and ISERROR. Here is a brief example:

if iserror formula excel

IFERROR in Google Sheets

The IFERROR Function works exactly the same in Google Sheets as in Excel:

iferror function google sheets

IFERROR Examples in VBA

VBA does not have a built-in IFERROR Fucntion, but you can also access the Excel IFERROR Function from within VBA:

Application.WorksheetFunction gives you access to many (not all) Excel functions in VBA.

Typically IFERROR is used when reading values from cells.  If a cell contains an error, VBA may throw an error message when attempting to process the cell value.  Try this out with the example code below (where cell B2 contains an error):

vba iferror example

The code assigns cell B2 to a variable. The second variable assignment throws an error because the cell value is #N/A, but the first works fine because of the IFERROR function.

You can also use VBA to create a formula containing the IFERROR Function:

vba code generator

Error handling in VBA is much different than in Excel. Typically, to handle errors in VBA, you will use VBA Error Handling. VBA Error Handling looks like this:

Notice we use If Err.Number <> 0 Then to identify if an error has occurred.  This is a typical way to catch errors in VBA. However, the IFERROR Function has some uses when interacting with Excel cells.

Excel Practice Worksheet

Practice Excel functions and formulas with our 100% free practice worksheets!

  • Automatically Graded Exercises
  • Learn Excel, Inside Excel!