Excel VBA IsError Function
VBA IsError Function: The IsError function in VBA returns a Boolean value showing whether the specified Expression represents an error or not.
Syntax
IsError (Expression)
Parameter
Expression (required)- This parameter represents the variant that you want to check.
Return
This function returns a Boolean value True if the given expression represents an error else it returns False.
Example 1
Sub IsError_Example1() Dim var Dim isErr As Boolean var = "Hello" ' sets var1 to the string "Hello" isErr = IsError(var1) ' The variable isErr1 is now equal to False. Cells(1, 1).Value = "The isError will return" Cells(1, 2).Value = isErr End Sub
Output
The isError will return | FALSE |
Example 2
Sub IsError_Example2() Dim var Dim isErr As Boolean var = CVErr(14) ' sets var value to Error 14 isErr = IsError(var) ' The variable isErr will return True. Cells(1, 1).Value = "The isError will return" Cells(1, 2).Value = isErr End Sub
Output
The isError will return | TRUE |