DateSerial VBA function – How to create date from date parts

1. DateSerial VBA Function – Description

The DateSerial VBA function  returns a date composed of arguments such as year , month , day . If in VBA you have numbers representing year, month, day and you want to compose a date from them, use the DateSerial function. In case you want to combine elements not date but time, use the VBA TimeSerial function .

2. VBA DateSerial function – Syntax

DateSerial (Year As Integer, Month As Integer, Day As Integer)

Year – A number that repeats a year within a date

Month – A number representing the month of the date

Day – A number representing the month of the date

Function return:  Date / Date

3. VBA DateSerial function – Example

How to use DateSerial function in VBA Excel? Below is an example of using the DateSerial function in the VisualBasic Editor.

Example 1:

Range ("A1") = DateSerial (2018, 7, 16)
MsgBox DateSerial (2018, 7, 16)

Example 2:

Dim intYear As Integer
Dim intMonth As Integer
Dim intDay As Integer

intYear = 2019
intMonth = 12
intDay = 30

MsgBox DateSerial (intYear, intMonth, intDay)
Range ("A2") = DateSerial (intYear, intMonth, intDay)
Excel VBA functions - DateSerial VBA function
Excel VBA functions – DateSerial VBA function

4. VB DateSerial function – Additional information

  • lack

5. DateSerial VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions .

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: