VBA Function: IsEmpty
The VBA IsEmpty function returns False if the variable has been initialized or True if it has not.
Usage:
IsEmpty(variable)
Example of Usage
The IsEmpty function checks if the variable hello has been initialized or not to avoid displaying the message multiple times on the screen:
Public hello
'Procedure that says hello only once
Sub sayHello()
If IsEmpty(hello) Then
MsgBox "Hello ;-)"
hello = 1
End If
End Sub
'Examples of calling the procedure
Sub example()
sayHello 'Result: displays the message
sayHello 'Result: does not display the message
sayHello 'Result: does not display the message
End Sub
If needed, it is possible to assign the value Empty back to the variable:
'Examples of calling the procedure
Sub example()
sayHello 'Result: displays the message
sayHello 'Result: does not display the message
hello = Empty
sayHello 'Result: displays the message
End Sub