VBA IsEmpty function in Excel is categorized as an Information function in VBA. It is a built-in function in MS Office Excel VBA. This function checks specified Expression or Variant is empty or not. It has one input parameter. It returns a boolean value (True or False). If specified variant is empty then it returns True, Otherwise it returns False.
We can use this function as a worksheet function and also used in VBA. This function can be use in either procedure or function in a VBA editor window in Excel. VBA IsEmpty 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 IsEmpty function, where we can use this VBA IsEmpty function and real-time examples.
- Overview
- Syntax of VBA IsEmpty Function
- Parameters or Arguments
- Where we can apply or use VBA IsEmpty Function?
- Example 1: Check an expression(“VBAF1.COM”) is empty or not
- Example 2: Check given expression(12345) is empty or not
- Example 3: Check an expression(Null) is empty or not
- Example 4: Check an expression(Empty) is empty or not
- Example 5: Check a variable(undeclared) is empty or not
- Instructions to Run VBA Macro Code
- Other Useful Resources
Syntax of VBA IsEmpty Function
The syntax of the VBA IsEmpty function is
IsEmpty(Expression)
The VBA IsEmpty function returns a boolean value either True or False.
Parameters or Arguments
The IsEmpty function has one input parameter or argument.
Where
Expression: It is a required parameter. The Expression that you want to evaluate.
Where we can apply or use VBA IsEmpty Function?
We can use this VBA IsEmpty 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 empty or not
Here is a simple example of the VBA IsEmpty function. This below example checks the specified string(“VBAF1) is empty or not. The output of below macro is FALSE
'Check an expression("VBAF1") is empty or not Sub VBA_IsEmpty_Function_Ex1() 'Variable declaration Dim iExpression As String Dim sOutput As Boolean iExpression = "VBAF1" sOutput = IsEmpty(iExpression) 'Display output message MsgBox "The expression('VBAF1') is empty or not : " & sOutput, vbInformation, "VBA IsEmpty Function" End Sub
Output: Here is the screen shot of the first example output.
Example 2: Check given expression(12345) is empty or not
Here is another example of the VBA IsEmpty function. This below example checks the specified number(12345) is empty or not. The output of below macro is FALSE.
'Check given expression(12345) is empty or not Sub VBA_IsEmpty_Function_Ex2() 'Variable declaration Dim iExpression As Integer Dim sOutput As Boolean iExpression = 12345 sOutput = IsEmpty(iExpression) 'Display output message MsgBox "The expression(12345) is empty or not : " & sOutput, vbInformation, "VBA IsEmpty Function" End Sub
Output: Here is the screen shot of the second example output.
Example 3: Check an expression(Null) is empty or not
Here is a simple example of the VBA IsEmpty function. This below example checks the specified variable(Null) is empty or not. The output of below macro returns False.
'Check an expression(Null) is empty or not Sub VBA_IsEmpty_Function_Ex3() 'Variable declaration Dim iExpression Dim sOutput As Boolean iExpression = Null sOutput = IsEmpty(iExpression) 'Display output message MsgBox "The expression(Null) is empty or not : " & sOutput, vbInformation, "VBA IsEmpty Function" End Sub
Output:Here is the screen shot of the third example output.
Example 4: Check an expression(Empty) is empty or not
Here is a simple example of the VBA IsEmpty function. This below example checks the specified string(“ABC123”) is numeric or not. The output of below macro is TRUE.
'Check an expression(Empty) is empty or not Sub VBA_IsEmpty_Function_Ex4() 'Variable declaration Dim iExpression Dim sOutput As Boolean iExpression = Empty sOutput = IsEmpty(iExpression) 'Display output message MsgBox "The expression(Empty) is empty or not : " & sOutput, vbInformation, "VBA IsEmpty Function" End Sub
Output: Here is the screen shot of the fourth example output.
Example 5: Check a variable(undeclared) is empty or not
Here is a simple example of the VBA IsEmpty function.This below example checks the specified undeclared variable is empty or not. The output of below macro is TRUE.
'Check a variable(undeclared) is empty or not Sub VBA_IsEmpty_Function_Ex5() 'Variable declaration Dim iExpression Dim sOutput As Boolean sOutput = IsEmpty(iExpression) 'Display output message MsgBox "The expression(undeclared variable) is empty or not : " & sOutput, vbInformation, "VBA IsEmpty 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