Excel VBA IsEmpty Function
VBA IsEmpty Function: The IsEmpty function in VBA returns a Boolean value showing whether the specified Expression is Empty (variant has not been declared) or not.
Syntax
IsEmpty (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 is empty else it returns False.
Example 1
Sub IsEmpty_Example1() Dim var As Integer Dim isEmp As Boolean var = 10 isEmp = IsEmpty(var) ' The variable will return False. Cells(1, 1).Value = "The IsEmpty will return" Cells(1, 2).Value = isEmp End Sub
Output
The IsEmpty will return | FALSE |
Example 2
Sub IsEmpty_Example2() Dim isEmp As Boolean 'The variable var is not been declared isEmp = IsEmpty(var) ' The variable will return True. Cells(1, 1).Value = "The IsEmpty will return" Cells(1, 2).Value = isEmp End Sub
Output
The IsEmpty will return | TRUE |
Example 3
Sub IsEmpty_Example3() Dim var Dim isEmp As Boolean 'The variable var is initialized with Null var = Null isEmp = IsEmpty(var) ' The variable will return False. Cells(1, 1).Value = "The IsEmpty will return" Cells(1, 2).Value = isEmp End Sub
Output
The IsEmpty will return | FALSE |