Hi I am using this past thread How To Get The Current Year Using Vba
The answer was to use Year(Date)
so I implemented it like this:
Dim a As Integer
a = Year(Date)
But when I tried to use it, I am getting an error
Runtime 13 : Type Mismatch
In Excel VBA, you want to use
DATEPART
. Assuming that the data that you're trying to get the year from is valid (which is hard to know from the little information in your question).From here:
and this specific example:
I suspect your type mismatch is somewhere else because
Year(Date)
is valid. The other option is to useYear(Now)
I suspect you have declared the variable you are trying to assign to as something weird because VBA will make a lot of bizarre casts for you
Be sure that you have
Option Explicit
set at the top of your module and you compile the code.