VBA IsDate Function

VBA IsDate Function in Excel

VBA IsDate function in Excel is categorized as an Information function in VBA. It is a built-in function in MS Office Excel VBA. Checks specified Expression or Variant is Date or not. It has one input parameter. 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 use as a VBA function. This function use 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 Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply