VBA DateSerial Function

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

DateSerial Description

Returns a date given a year, month, and day value.

Simple DateSerial Examples

Here is a simple DateSerial example:

Sub DateSerial_Example()
    MsgBox DateSerial(2019, 4, 1)
End Sub

This code will return 04/01/2019.

DateSerial Syntax

In the VBA Editor, you can type  “DateSerial(” to see the syntax for the DateSerial Function:

The DateSerial function contains 3 arguments:

Year: Integer value between 100 and 9999, or a numeric expression

Month: Integer value. Any numeric expression.

Day: Integer value. Any numeric expression.

Examples of Excel VBA DateSerial Function

MsgBox DateSerial(2019, 40, 1)

Result: 04/01/2022

Based on the example above, we can see that the 40th month is April 2022, starting in January 2019.

MsgBox DateSerial(2019, -5, 10)

Result: 07/10/2018

MsgBox DateSerial(2019, -5, -10)

Result: 06/20/2018

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples