VBA IsNull function in Excel is categorized as an Information function in VBA. It is a built-in function in MS Office Excel VBA. The VBA IsNull function checks specified Expression is Null or not. This function has one input parameter. Returns a Boolean value (True or False). If specified expression is null then it returns True, Otherwise it returns False.
We can use this function in VBA and can’t use this function in Excel. Use this VBA IsNull 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 IsNull function, where we can use this VBA IsNull function and real-time examples.
- Overview
- Syntax of VBA IsNull Function
- Parameters or Arguments
- Where we can apply or use VBA IsNull Function?
- Example 1: Check an expression(“vbaf1”) is null or not
- Example 2: Check an expression(12345) is null or not
- Example 3: Check an expression(unassigned variable) is null or not
- Example 4: Check an expression(empty string) is null or not
- Example 5: Check an expression(Null) is null or not
- Instructions to Run VBA Macro Code
- Other Useful Resources
Syntax of VBA IsNull Function
The syntax of the VBA IsNull function is
IsNull(Expression)
The VBA IsNull function returns a Boolean value either True or False.
Parameters or Arguments
The IsNull function has one input parameter or argument.
Where
Expression: It is a required parameter. The expression is an argument that you want to evaluate.
Where we can apply or use VBA IsNull Function?
We can use this VBA IsNull 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(“vbaf1”) is null or not
Here is a simple example of the VBA IsNull function. This below example checks the specified expression is null or not. The output of below macro is FALSE.
'Check an expression("vbaf1") is null or not Sub VBA_IsNull_Function_Ex1() 'Variable declaration Dim iExpression As String Dim sOutput As Boolean iExpression = "vbaf1" sOutput = IsNull(iExpression) 'Display output message MsgBox "The expression is null or not : " & sOutput, vbInformation, "VBA IsNull Function" End Sub
Output: Here is the screen shot of the first example output.
Example 2: Check an expression(12345) is null or not
Here is a simple example of the VBA IsNull function. This below example checks the specified expression is null or not. The output of below macro is FALSE.
'Check an expression(12345) is null or not Sub VBA_IsNull_Function_Ex2() 'Variable declaration Dim iExpression As Integer Dim sOutput As Boolean iExpression = 12345 sOutput = IsNull(iExpression) 'Display output message MsgBox "The expression is null or not : " & sOutput, vbInformation, "VBA IsNull Function" End Sub
Output:Here is the screen shot of the second example output.
Example 3: Check an expression(unassigned variable) is null or not
Here is a simple example of the VBA IsNull function. This below example checks the specified expression is null or not. The output of below macro is FALSE.
'Check an expression(unassigned variable) is null or not Sub VBA_IsNull_Function_Ex3() 'Variable declaration Dim iExpression As Double Dim sOutput As Boolean sOutput = IsNull(iExpression) 'Display output message MsgBox "The expression is null or not : " & sOutput, vbInformation, "VBA IsNull Function" End Sub
Output:Here is the screen shot of the third example output.
Example 4: Check an expression(empty string) is null or not
Here is another example of the VBA IsNull function. This below example checks the specified expression is null or not. The output of below macro is FALSE.
'Check an expression(empty string) is null or not Sub VBA_IsNull_Function_Ex4() 'Variable declaration Dim iExpression As String Dim sOutput As Boolean iExpression = "" sOutput = IsNull(iExpression) 'Display output message MsgBox "The expression is null or not : " & sOutput, vbInformation, "VBA IsNull Function" End Sub
Output:Here is the screen shot of the fourth example output.
Example 5: Check an expression(Null) is null or not
Here is one more example of the VBA IsNull function. This below example checks the specified expression is null or not. The output of below macro is TRUE.
'Check an expression(Null) is null or not Sub VBA_IsNull_Function_Ex5() 'Variable declaration Dim iExpression Dim sOutput As Boolean iExpression = Null sOutput = IsNull(iExpression) 'Display output message MsgBox "The expression is null or not : " & sOutput, vbInformation, "VBA IsNull Function" End Sub
Output:Here is the screen shot of the fifth 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