VBA DATESERIAL Function

HomeVBA Functions LIST (Category Wise)How to use the VBA DATESERIAL Function (Syntax + Example)

What is VBA DATESERIAL Function

how to use it

To use VBA's DATESERIAL function you need to understand its syntax and arguments:

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 use DATESERIAL Function in VBA

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:

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

Below are some important points which you need to take care while using DATESERIAL function in VBA.

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

Related Functions

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.