VBA IsError Function

Associated Files Download Links

IsError Description

Used to check for error values.

Simple IsError Examples

MsgBox IsError(1/2)

Result: False

MsgBox IsError(CvErr(0))

Result: True

IsError Syntax

In the VBA Editor, you can type  “IsError(” to see the syntax for the IsError Function:

The IsError function contains an argument:

Expression: An expression that will be tested.

Examples of Excel VBA IsError Function

Function Divide(a As Double, b As Double)
    On Error GoTo error_handler
    Divide = a / b
    Exit Function
    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)
End Sub

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