Function isLeapYear(ByVal YY As Long) As Boolean
isLeapYear = IIf(YY Mod 100 = 0, YY Mod 400 = 0, YY Mod 4 = 0)
End Function
Ziggy12 said:Want to test for a leap year in VBA. How do I check if the result of dividing the year by 4 is an whole number?
Hi Will:Wil Moosa said:Public Function IsLeapYear(Y As Integer)
IsLeapYear = Month(DateSerial(Y, 2, 29)) = 2
End Function
Works too but... Both code replies with true or not true when the input is the year only (no dd and mm). In my case the input is day, month ánd year what results in wrong response.
Example: Input of cell A1 is 12-12-2004. However formatted to "yyyy" Cell A2 (formula =IsleapYear) shows "not true" and not "true".
Is there a way to get this fixed?
Function isyLeapYear(ByVal Date1 As Date) As Boolean
YY = Year(Date1)
isyLeapYear = IIf(YY Mod 100 = 0, YY Mod 400 = 0, YY Mod 4 = 0)
End Function