The VBA IsMissing Function

Description

The VBA IsMissing function tests if an Optional argument to a procedure is missing.

The function returns True if the supplied argument has not been supplied and returns False if the argument has been supplied.

The syntax of the IsMissing function is:

IsMissing( ArgName )

Where the supplied ArgName is the name of the argument that you want to test.


VBA IsMissing Function Example

The following VBA code shows a simple Sub procedure that receives an optional Variant argument. The procedure uses the IsMissing function, to test whether the Variant argument is missing or has been supplied.

' Test if an optional argument to a procedure is missing.
Sub mySub( Optional var1 As Variant )
if IsMissing( var1 ) Then
' Code to run if var1 has not been supplied.
Else
' Code to run if var1 has been supplied.
End If
End Sub

The above VBA Sub procedure accepts an optional Variant argument, var1. The procedure then uses the IsMissing function to test if var1 is missing or has been supplied.

The result of the IsMissing function is then used to decide which section of code is subsequently executed.