Get Next Year from Today’s Date using Excel VBA Functions. Year plays an important role as part of date. It helps in data analysis to summarize data, create graphs and dashboards. We also format year using format function.
VBA Find Next Year From Date:
Let us see the procedure how to get name of the year from today’s date using ‘Year’ and ‘DateAdd’ function.
'Procedure to Get Year From specified Date Sub VBA_Get_Year_From_Specified_Date() 'Variable declaration Dim sYear As Integer 'Retrieve Year from date sYear = DateAdd("y", 1, Year("01/01/2020")) 'Display Year MsgBox "If specified date is '01/01/2020' then" & vbCrLf & _ "Year is : " & sYear, vbInformation, "Year From Date" End Sub
Here is the output screen shot of the above macro procedure.
VBA Get Year from Today’s Date:
Let us see the procedure how to get name of the year from today’s date using Date, Year and DateAdd functions.
'Procedure to Get Year From todays Date Sub VBA_Get_Year_From__Todays_Date() 'Variable declaration Dim sYear As Integer 'Retrieve Year from date sYear = DateAdd("y", 1, Year(Date)) 'Display Year MsgBox "If today's date is " & Date & " then" & vbCrLf & _ "year is : " & sYear, vbInformation, "Year From Date" End Sub
Let us see the output screenshot of the above macro procedure for your reference.
Explanation: In the above procedures you can see Date, Year and DateAdd VBA functions. Here date displays date. Year function helps to display year from date.
Format Year of date:
We have different format methods to format year. You can find output in an immediate window.
'Format Year from date Sub VBA_Format_Year() 'Variable declaration Dim iYear As Integer iYear = Format("01/01/2018", "yy") Debug.Print iYear iYear = Format("01/01/2018", "yyyy") Debug.Print iYear End Sub
Output Screenshot: Here is the output screenshot for your reference.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog