VBA IsDate Function

Publication Date :

Blog Author :

Table Of Contents

arrow

Excel VBA IsDate Function

IsDate is the VBA function that tests whether the given value is the date or not. If the supplied value or range reference value is the date value, we will get the result as “TRUE.” On the other hand, if the value is not date, we will get the result as “FALSE.” So, the result is a BOOLEAN value, i.e., TRUE or FALSE.

Below is the syntax of the IsDate function.

VBA IsDate Formula

The expression is nothing but the value we are trying to test, whether it is the date or not.

How to use the VBA IsDate Function?

We will test whether the value “5.01.19” is a date value or not.

For this first start, the excel macro procedure.

Code:

Sub IsDate_Example1()

End Sub
Example 1

Define the variable to store the date value, and since the value will be the date value, assign the data type as “Date” only.

Code:

Sub IsDate_Example1()

Dim MyDate As Date

End Sub
Example 1.1

Now assign the value of “5.1.19” to the variable “MyDate.”

Code:

Sub IsDate_Example1()

Dim MyDate As Date

MyDate = "5.1.19"

End Sub
VBA IsDate Example 1.2

Open the message box in VBA now.

Code:

Sub IsDate_Example1()

Dim MyDate As Date

MyDate = "5.1.19"

MsgBox(

End Sub
 Example 1.3

In this message box, we will test whether the supplied date value to the variable “MyDate” is the date or not by using the “IsDate” function. First, open the “IsDate” function.

Code:

Sub IsDate_Example1()

Dim MyDate As Date

MyDate = "5.1.19"

MsgBox IsDate(

End Sub
VBA IsDate Example 1.4

The expression is the value we are testing to find whether it is Date or not. Since we have already stored the value to the variable “MyDate,” supply the variable name only.

Code:

Sub IsDate_Example1()

Dim MyDate As Date

MyDate = "5.1.19"

MsgBox IsDate(MyDate)

End Sub
 Example 1.5

Now run the code and see what we get in the message box.

VBA IsDate Example 1.6

The result is TRUE.

You must wonder how it recognized the value “5.1.19” as the date.

It has returned the result as TRUE because when you look at the given value “5.1.19,” it is the short form of the date “05.01.2019,” so Excel is brilliant enough to recognize it as a date, so the result is TRUE.

 Example 1.7

Now here comes the tricky thing, for the same value, what we will do is we will change the short form of the year from 19 to 2019.

Code:

Sub IsDate_Example1()

Dim MyDate As String

MyDate = "5.1.2019"

MsgBox IsDate(MyDate)

End Sub
Example 2.0

Now, run the code and see the result.

VBA IsDate Example 2.1

This time it has returned the result as FALSE because the “day and month” portion of the date is in short form, but the year part is in full form of “YYYY,” so ISDATE cannot recognize it has a date, so the result is FALSE.

Now, look at the code below.

Code:

Sub IsDate_Example1()

Dim MyDate As String

MyDate = "05.01.2019"

MsgBox IsDate(MyDate)

End Sub
 Example 2.2

We have mentioned a full day and full month format by using 0. Let us run the code and see the result of the IsDate function.

This time also we go got the result as FALSE.

VBA IsDate Example 2.3

Now, change the code as follows.

Code:

Sub IsDate_Example1()

Dim MyDate As String

MyDate = "05/01/2019"

MsgBox IsDate(MyDate)

End Sub
 Example 2.4

Instead of the dot (.) as the separator, we have entered forward-slash (/) as the separator. Now run the code and see the result.

VBA IsDate Example 2.5

This time we got the result as TRUE.

We have told you at the beginning of the article that “Date” is a sensitive thing.

Now what we will do is we will merge the date and time.

Code:

Sub IsDate_Example1()

Dim MyDate As String

MyDate = "05/01/2019 15:26:24"

MsgBox IsDate(MyDate)

End Sub
 Example 2.6

We have added above the time portion of “15:26:24” in front of the date. Now, run the code and see the result.

VBA IsDate Example 2.7

This time, we also got the result TRUE because DATE and TIME in Excel are the same things and stored as serial numbers. The whole number represents the date portion, and decimal places represent the time portion.

Things to Remember here

  • The IsDate function returns the Boolean type result, i.e., TRUE or FALSE.
  • The IsDate function is available only as a VBA function.
  • Only valid formatted dates one can treat as the date. Else, it will treat as text values and return the result as FALSE.