The VBA YEAR Function

Related Functions:
VBA Day
VBA Month

Description

The VBA Year Function returns the four digit year from a supplied date.

The syntax of the function is:

Year( Date )

VBA Year Function Example

A simple example of the VBA Year function is shown below:

' Extract the year from the date "11/29/2015"
Const currDate = "11/29/2015"
Dim yearNum As Integer
yearNum = Year(currDate)
' The variable yearNum is now equal to 2015.

After running the above VBA code, the variable yearNum holds the value 2015.


VBA Year Function Error

If the Year function is supplied with a value that cannot be interpreted as a valid date, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box