VBA DATESERIAL Function (Syntax + Example)

Last Updated: June 22, 2023
puneet-gogia-excel-champs

- Written by Puneet

The VBA DATESERIAL function is listed under the date category of VBA functions. When you use it in a VBA code, it returns a valid date as per VBA’s date format by the supplied day, month, and year. In simple words, you can create a date with day, month, and year input. It’s just like the DATE function in the worksheet.

Syntax

DateSerial(Year, Month, Day)

Arguments

  • Year: An integer to use as the year in the date.
  • Month: An integer to use as the month in the date.
  • Day: An integer to use as the day in the date.

Example

To practically understand how to use VBA DATESERIAL function, you need to go through the below example where we have written a vba code by using it:

example-vba-dateserial-function
Sub example_DATESERIAL()
Range("A1").Value = DateSerial(2019, 5, 15)  
End Sub

In the above example, we have used the DATESERIAL to create a date with 2019 as a year, 5 months, and 15 as a day and as a result, it has returned 15-May-19.

Notes

  • Make sure to use the four-digit value for the years.
  • If you add the day number out of the maximum number of days in a month, it will return the date by adding excess days to the next month.
  • If you add the month number out of the maximum number of months in a year, it will return the date by adding excess months to the next year.