VBA Year Function

Year Description

Returns a four-digit year (a number from 1900 to 9999) given a date value.

Simple Year Examples

Here is a simple Year example:

Sub Year_Example()
    MsgBox Year("1/1/2019")
End Sub

This code will return 2019.

Year Syntax

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

The Year function contains an argument:

Date: A valid date.

Examples of Excel VBA Year Function

MsgBox Year("1/1/1999")

Result: 1999

MsgBox Year(#1/1/2001 1:30:00 AM#)

Result: 2001

MsgBox Year("1/1/05")

Result: 1905

MsgBox Year(Date)

Result will be the year of the current system date.