# ISERROR Function Examples in Excel, VBA, & Google Sheets

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on March 16, 2024

This tutorial demonstrates how to use the ISERROR Function in Excel to test if a cell results in an error.

## How to use the ISERROR Function

The ISERROR Function checks if a calculation results in an error.

``=ISERROR(A2)``

### IF ISERROR Replaced by IFERROR

Prior to Excel 2007, the ISERROR Function was commonly used along with the IF Function to output a second calculation if the first calculation resulted in an error.

``=IF(ISERROR(C2/B2),"Zero Stock",C2/B2)``

However, in Excel 2007, the IFERROR Function was introduced, making the IF / ISERROR combo obsolete.

``=IFERROR((C2/B2),"Zero Stock")``

### ISERR and ISNA

The ISERROR Function returns TRUE if any error occurs.

There are two other error checking “is” functions:

``````=ISNA(A2)
=ISERR(A2)``````

Also, in addition to the IFERROR Function, there is the IFNA Function.

These functions are important because many formula errors are a result of bad formulas, but #N/A errors are often valid. For example, if you use the VLOOKUP Function and the lookup value is not found, the formula will return #N/A.

``=VLOOKUP(A2,\$D\$2:\$E\$7,2,FALSE)``

By applying the IFNA Function to the VLOOKUP, you can handle valid #N/A errors, while not handling other formula errors (so you don’t overlook those other errors).

``=IFNA(VLOOKUP(A2,\$D\$2:\$E\$7,2,FALSE),VLOOKUP(A2,\$G\$2:\$H\$7,2,FALSE))``

### Other Logical Functions

Excel / Google Sheets contain many other logical functions to perform other logical tests. Here is a list:

IF / IS Functions
iferror
iserror
isna
iserr
isblank
isnumber
istext
isnontext
isformula
islogical
isref
iseven
isodd

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

## ISERROR Examples in VBA

You can also use ISERROR in VBA:

``MsgBox IsError(1/2)``

Result: False

``MsgBox IsError(CvErr(0))``

Result: True

This example shows using ISERROR to test the result of a function.

``````Function Divide(a As Double, b As Double)
On Error GoTo error_handler
Divide = a / b
Exit Function
error_handler:
Divide = CVErr(Err.Number)
End Function

Sub IsError_Example2()
MsgBox "IsError(1/2) is " & IsError(Divide(1, 2))
MsgBox "IsError(1/0) is " & IsError(Divide(1, 0))
End Sub``````

Result: IsError(1/2) is False
IsError(1/0) is True

Using IsError, you can check cells on Excel Sheet.

``````Sub CheckIfError(strRange As String)
Dim cell As Range

For Each cell In Range(strRange)
cell.Offset(0, 1) = IsError(cell)
Next
End Sub

Sub IsError_Example1()
CheckIfError "C2:C5"
CheckIfError "B9:B12"
End Sub``````