Returns a Boolean value indicating whether a variable has been initialized.
IsEmpty(expression)
The expression argument can be any numeric or string expression. However, because IsEmpty is used to determine if individual variables are initialized, the expression argument is most often a single variable name.
IsEmpty returns True if the variable is uninitialized, or is explicitly set to Empty; otherwise, it returns False. False is always returned if expression contains more than one variable. IsEmpty only returns meaningful information for variants.
IsArray Function, IsDate Function, IsError Function, IsMissing Function, IsNull Function, IsNumeric Function, IsObject Function, TypeName Function, Variant Data Type, VarType Function.
This example uses the IsEmpty function to determine whether a variable has been initialized.
MyCheck = IsEmpty(MyVar) ' Returns True.= Null ' Assign Null.= IsEmpty(MyVar) ' Returns False.= Empty ' Assign Empty.= IsEmpty(MyVar) ' Returns True.
The following example uses the IsEmpty function to determine whether a variable has been initialized. If it hasn’t been initialized, a message prompts the user to enter the initial value.
Sub CheckInitialized() ' Declare variables. Dim varTest As Variant, varInit As Variant ' Test variable. If IsEmpty(varTest) Then varInit = MsgBox("Variable uninitialized; initialize now?", _ vbOKCancel) If varInit = vbOK Then ' If user clicked OK, initialize varTest. varTest = InputBox("Please enter the value for the "& _ "variable.") ' Display confirmation. MsgBox "Variable 'varTest' initialized to " & varTest End If End IfSub