Year VBA Function – How to calculate year from date

Last Updated on January 11, 2023 by token

1. Year VBA function – Description

The Year VBA function returns a number representing the year of a given date. So if we want Excel VBA to return to us numbers corresponding to subsequent years, we should use this function. It should be remembered that the date from which we want to obtain the year number should be taken from the variable or saved in the VB code in the date format, i.e. YYYY-MM-DD .

2. VBA Year function – Syntax

Year (Date)

Date : The date from which we want to get the next number corresponding to the year number. The date should be in the YYYY-MM-DD format .

Function return: Integer / Numeric value.

3. VBA Year function – Example

How to use Year function in VBA Excel? Below is an example of using the Year function in the VisualBasic Editor.

Sub YearFunctionExample ()

MsgBox Year ("2017-12-31")

Dim DatDate As Date
DatDate = Date
MsgBox Year (DatDate)

MsgBox Year (Date)

Range ("A1") = Year ("02-28 2018")

End Sub
Excel VBA functions - Year VBA function
Excel VBA functions – Year VBA function

4. VB Year function – Additional information

  • The date from which we want to obtain the year number should have the Date data type or be saved in the YYYY-MM-DD format.

5. Year VisualBasic function – Where to apply?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016, Excel 2019, Excel 2021, Excel 365.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address: VBA functions .

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: