VBA IsMissing Function

VBA IsMissing Function

Objective of VBA IsMissing Function

VBA IsMissing function is categorized as an Information function in VBA. It is a built-in function in MS Office Excel VBA. This function checks specified an optional argument is missing or not. It has one input parameter. It returns a Boolean value (True or False). If specified optional argument is empty then it returns True, Otherwise it returns False. We can use this function as a worksheet function and also used in VBA. This function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA IsMissing function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the IsMissing function, where we can use this VBA IsMissing function and real-time examples.

Syntax of VBA IsMissing Function

The syntax of the VBA IsMissing function is

IsMissing(ArgName)

The VBA IsMissing function returns Boolean value either True or False. If ArgName argument is left blank then, it returns True.
Note: This function only works for Variant data type variables.This function cannot be applied for data types like Boolean, Integer, Double, Date, etc. These type of variables initialized automatically. equivalent values. Please find below examples for better understand.

Parameters or Arguments

The IsMissing function has one input parameter or argument.
Where
ArgName: It is a required parameter. The ArgName is an optional argument that you want to evaluate.

Where we can apply or use VBA IsMissing Function?

We can use this VBA IsMissing function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Check an optional argument (variant) is missing or not

Here is a simple example of the VBA IsMissing function. This below example checks the for the optional argument is missing or not. The output of below macro is TRUE.

'Check an optional argument (variant data type) is missing or not
Sub VBA_IsMissing_Function_Ex1(Optional iArgument As Variant)
    
    'Variable declaration
    Dim sOutput As Boolean
    
    sOutput = IsMissing(iArgument)
   
    'Display output message
    MsgBox "The optional argument is missing or not : " & sOutput, vbInformation, "VBA IsMissing Function"
    
End Sub

Output: Here is the screen shot of the first example output.

Example 2: Check an optional argument(Boolean) is missing or not

Here is a another example of the VBA IsMissing function. This below example checks for the optional argument is missing or not.

'Check an optional argument(Boolean data type) is missing or not
Sub VBA_IsMissing_Function_Ex2(Optional iArgument As Boolean)
    
    'Variable declaration
    Dim sOutput As Boolean
    
    sOutput = IsMissing(iArgument)
   
    'Display output message
    MsgBox "The optional argument is missing or not : " & sOutput, vbInformation, "VBA IsMissing Function"
    
End Sub

Output: The below specified example macro doesn’t work. Because a Boolean data type default consists of False value.

Example 3: Check an optional argument is provided or not

Here is a simple example of the VBA IsMissing function. This below example checks the for the optional argument is missing or not. Here we have specified function, which is used in the procedure to check argument is missing or not. The output of below macro is TRUE.
User defined Function:

' Function procedure definition.
Function OutputValue(Optional iArgument As Variant)
    If IsMissing(iArgument) Then
        OutputValue = True
    Else
        OutputValue = False
    End If
End Function

Note: The above specifed user defined function used in the below procedure.

'Check an optional argument is provided or not
Sub VBA_IsMissing_Function_Ex3()
    
    'Variable declaration
    Dim sOutput As Boolean
    
    sOutput = OutputValue()
       
    'Display output message
    MsgBox "The optional argument is missing or not : " & sOutput, vbInformation, "VBA IsMissing Function"
    
End Sub

Output:Here is the screen shot of the third example output.

Instructions to use Macro Codes

Here are the step by step instructions to use the VBA IsMissing function in Excel VBA.

  • Open an Excel workbook.
  • Press Alt+F11 to open VBA Editor window.
  • Go to Insert menu and click on module from the available options.
  • Copy above specified macros to the VBA editor.
  • Select any procedure from above codes and click on ‘Run’ command or use Keyboard shortcut ‘F5’.

List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.

VBA Information Functions List of VBA Functions

Leave a Comment

Your email address will not be published. Required fields are marked *