Return to VBA Code Examples

VBA IsError Function

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
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

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples