VBA IsDate Function

VBA IsDate Function

Objective of VBA IsDate Function

VBA IsDate function is categorized as an Information function in VBA. It is a built-in function in MS Office Excel VBA. This function checks specified Expression or Variant is Date or not. It has one input parameter. It returns a Boolean value (True or False). If specified variant is valid Date then it returns True, Otherwise it returns False. We can’t use this function as a worksheet function. We can only used as a VBA function. This function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA IsDate 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 IsDate function, where we can use this VBA IsDate function and real-time examples.

Syntax of VBA IsDate Function

The syntax of the VBA IsDate function is

IsDate(Expression)

The VBA IsDate function returns a boolean value either True or False.

Parameters or Arguments

The IsDate function has one input parameter or argument.
Where
Expression: It is a required parameter. The Expression that you want to evaluate. It could be a date or time or a string in a date format

Where we can apply or use VBA IsDate Function?

We can use this VBA IsDate 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 expression(VBAF1) is Date or not

Here is a simple example of the VBA IsDate function. This below example checks the specified string(VBAF1) is Date or not. The output of below macro is FALSE.

'Check an expression(VBAF1) is Date or not
Sub VBA_IsDate_Function_Ex1()
    
    'Variable declaration
    Dim iExpression As String
    Dim sOutput As Boolean
    
    iExpression = "VBAF1"
    
    sOutput = IsDate(iExpression)
   
    'Display output message
    MsgBox "The expression('VBAF1') is Date or not : " & sOutput, vbInformation, "VBA IsDate Function"
    
End Sub

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

Example 2: Check given expression(12345) is Date or not

Here is another example of the VBA IsDate function. This below example checks the specified number(12345) is Date or not. The output of below macro is FALSE.

'Check given expression(12345) is Date or not
Sub VBA_IsDate_Function_Ex2()
    
     'Variable declaration
    Dim iExpression As Integer
    Dim sOutput As Boolean
    
    iExpression = 12345
    
    sOutput = IsDate(iExpression)
   
    'Display output message
    MsgBox "The expression(12345) is Date or not : " & sOutput, vbInformation, "VBA IsDate Function"
    
End Sub

Output: Here is the screen shot of the second example output.
VBA IsDate Function

Example 3: Check an expression(12:12:12 PM) is Date or not

Here is a simple example of the VBA IsDate function. This below example checks the specified variable(12:12:12 PM) is Date or not. This function considers time as date variable. The output of below macro returns TRUE.

'Check an expression(12:12:12 PM) is Date or not
Sub VBA_IsDate_Function_Ex3()
    
   'Variable declaration
    Dim iExpression As Date
    Dim sOutput As Boolean
    
    iExpression = "12:12:12 PM"
    
    sOutput = IsDate(iExpression)
   
    'Display output message
    MsgBox "The expression(12:12:12 PM) is Date or not : " & sOutput, vbInformation, "VBA IsDate Function"
    
End Sub

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

Example 4: Check an expression(Jan 01, 2018) is Date or not

Here is a simple example of the VBA IsDate function. This below example checks the specified variable(Jan 01, 2018) is date or not. The output of below macro is TRUE.

'Check an expression(Jan 01, 2018) is Date or not
Sub VBA_IsDate_Function_Ex4()
    
    'Variable declaration
    Dim iExpression As Date
    Dim sOutput As Boolean
    
    iExpression = "Jan 01, 2018"
    
    sOutput = IsDate(iExpression)
   
    'Display output message
    MsgBox "The expression(Jan 01, 2018) is Date or not : " & sOutput, vbInformation, "VBA IsDate Function"
    
End Sub

Output: Here is the screen shot of the fourth example output.
VBA IsDate Function

Example 5: Check a variable(01/01/2018 12:12 PM) is Date or not

Here is a simple example of the VBA IsDate function.This below example checks the specified undeclared variable is Date or not. The output of below macro is TRUE.

'Check a variable(01/01/2018 12:12 PM) is Date or not
Sub VBA_IsDate_Function_Ex5()
    
    'Variable declaration
    Dim iExpression As Date
    Dim sOutput As Boolean
    
    iExpression = "01/01/18 12:12 PM"
       
    sOutput = IsDate(iExpression)
   
    'Display output message
    MsgBox "The expression(01/01/18 12:12 PM) is Date or not : " & sOutput, vbInformation, "VBA IsDate Function"
    
End Sub

Output: Here is the screen shot of the fifth example output.
VBA IsDate Function

Instructions to use Macro Codes

Here are the step by step instructions to use the VBA IsDate 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.

List of VBA Functions

Leave a Comment

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