Friday, August 12, 2016

How to use the DATESERIAL Function (VBA)

Description

The Microsoft Excel DATESERIAL function returns a date given a year, month, and day value.

Syntax

The syntax for the DATESERIAL function in Microsoft Excel is:
DateSerial( year, month, day )

Parameters or Arguments

year
A numeric value between 100 and 9999 that represents the year value of the date.
month
A numeric value that represents the month value of the date.
day
A numeric value that represents the day value of the date.

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (as VBA Function)

The DATESERIAL function can only be used in VBA code in Microsoft Excel.
Let's look at some Excel DATESERIAL function examples and explore how to use the DATESERIAL function in Excel VBA code:
DateSerial(2004, 6, 30)
Result: "6/30/2004"

DateSerial(2004-1, 6, 30)
Result: "6/30/2003"

DateSerial(2004, 6-2, 14)
Result: "4/14/2004"
For example:
Dim LDate As Date

LDate = DateSerial(2004, 5, 31)
In this example, the variable called LDate would now contain the value of "5/31/2004".