VBA Year Function
Written by
Reviewed by
Last updated on July 19, 2021
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.
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!
Learn More!