VBA IsError function in Excel is categorized as an Information function in VBA. It is a built-in function in MS Office Excel. It checks specified Expression has an error or not. We have different error values such as #N/A, #DIV/0!, #NUM!, #NULL!,#NAME?, #REF! and #VALUE!. This function returns True if an expression contains an error, Otherwise it returns False.
The IsError function can be used in either Excel Worksheet function or as VBA function. The VBA IsError function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA IsError function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the IsError function, where we can use this VBA IsError function and real-time examples.
- Objective
- Syntax of VBA IsError Function
- Parameters or Arguments
- Where we can apply or use VBA IsArray Function?
- Example 1: Check an expression(0/100) is an error or not
- Example 2: Check an expression(100/0) is an error or not
- Example 3: Check an expression(CVErr(8)) is an error or not
- Instructions to Run VBA Macro Code
- Other Useful Resources
Syntax of VBA IsError Function
The syntax of the VBA IsError function is
IsError(Expression)
Note: This IsError function returns a Boolean value,
Parameters or Arguments:
There is one mandatory parameter or argument for the IsError Function.
Where
Expression: The Expression is a mandatory argument. The Expression that you want to test.
Where we can apply or use the VBA IsError Function?
We can use this VBA IsError function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.
Example 1: Check an expression(0/100) is an error or not
Here is a simple example of the VBA IsError function. This below example checks the specified expression(0/100) is an error or not. The output of below macro is TRUE.
'Check an expression(0/100) is an error or not Sub VBA_IsError_Function_Ex1() 'Variable declaration Dim iExpression Dim sOutput As Boolean iExpression = 0 / 100 sOutput = IsError(iExpression) 'Display output message MsgBox "The expression(0/100) is an error or not : " & sOutput, vbInformation, "VBA IsError Function" End Sub
Output: Here is the screen shot of the first example output.
Example 2: Check an expression(100/0) is an error or not
Here is a simple example of the VBA IsError function. This below example checks the specified expression(100/0) is an error or not. The output of below macro is TRUE.
Note: In the below example Sheets(“Sheet1”).Range(“A1”) has – ‘100/0’
'Check an expression(100/0) is an error or not Sub VBA_IsError_Function_Ex2() 'Variable declaration Dim sOutput As Boolean sOutput = IsError(Sheets("Sheet1").Range("A1")) 'Display output message MsgBox "The expression(100/0) is an error or not : " & sOutput, vbInformation, "VBA IsError Function" End Sub
Output: Here is the screen shot of the second example output.
Example 3: Check an expression(CVErr(8)) is an error or not
Here is a simple example of the VBA IsError function. This below example checks the specified expression(CVErr(8)) is an error or not. The output of below macro is TRUE.
'Check an expression(CVErr(8)) is an error or not Sub VBA_IsError_Function_Ex3() 'Variable declaration Dim iExpression Dim sOutput As Boolean iExpression = CVErr(8) sOutput = IsError(iExpression) 'Display output message MsgBox "The expression(CVErr(8)) is an error or not : " & sOutput, vbInformation, "VBA IsError Function" End Sub
Output: Here is the screen shot of the third example output.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays in Excel Blog
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers