VBA IsError Function
In this Article
IsError Description
Used to check for error values.
Simple IsError Examples
1 |
MsgBox IsError(1/2) |
Result: False
1 |
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
1 2 3 4 5 6 7 8 9 10 11 12 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
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!
Learn More!