VBA Function: IsMissing

The VBA IsMissing function returns False if the optional argument has been provided or True if it has not.

Usage:

IsMissing(variable)


Example of Usage

Using the IsMissing function to check if the optional argument lastName has been provided (and avoid displaying the name in the dialog box if it has not been provided):

Sub displayInfo(firstName, Optional lastName)
    
    If IsMissing(lastName) Then
        MsgBox "My name is " & firstName
    Else
        MsgBox "My name is " & firstName & " " & lastName
    End If
    
End Sub

Sub example()
    
    'Returns: My name is John
    displayInfo "John"
    
    'Returns: My name is John Smith
    displayInfo "John", "Smith"

End Sub