Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Get The Current Year Using Vba

Tags:

date

excel

vba

I am trying to get the current year using VBA. Is there any pre-build function available to find out the current year?

like image 813
Karthik Avatar asked Jul 14 '10 08:07

Karthik


People also ask

How do I get the current date in a macro?

Step 1: Create a subprocedure by naming the macro. Step 2: Declare the variable as “Date.” DATE function returns the result as date only, so the variable data type should be “Date.” Step 3: Assign the value to variable “k” as DATE function. Step 4: Now, the value of the variable “k” in the message box in VBA.

How do I use date formula in Excel VBA?

VBA Date Function – Example #1Step 1: Insert a new module in your Visual Basic Editor. Step 2: Define a sub-procedure to write create and save a macro. Step 3: Define a variable named CurrDate which can hold the value of the current date.

Which function returns the current date and time in VBA?

Description. The Microsoft Excel NOW function returns the current system date and time. The NOW function is a built-in function in Excel that is categorized as a Date/Time Function. It can be used as a worksheet function (WS) and a VBA function (VBA) in Excel.


2 Answers

Year(Date) 

Year(): Returns the year portion of the date argument.
Date: Current date only.

Explanation of both of these functions from here.

like image 56
mechanical_meat Avatar answered Sep 23 '22 03:09

mechanical_meat


Try =Year(Now()) and format the cell as General.

like image 22
Jeffrey Imran Avatar answered Sep 21 '22 03:09

Jeffrey Imran