I am trying to get the current year using VBA. Is there any pre-build function available to find out the current year?
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.
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.
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.
Year(Date)
Year()
: Returns the year portion of the date argument.Date
: Current date only.
Explanation of both of these functions from here.
Try =Year(Now())
and format the cell as General
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With