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:
1 2 3 |
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
1 |
MsgBox Year("1/1/1999") |
Result: 1999
1 |
MsgBox Year(#1/1/2001 1:30:00 AM#) |
Result: 2001
1 |
MsgBox Year("1/1/05") |
Result: 1905
1 |
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!