There are a few ways to determine whether a given year is a leap year. One way is to check the remainder after dividing the year by 400 and 100 and 4. I can't seem to follow how that works. Here are some more:
Determine if a Given Year is a Leap Year
My favorite is the one that checks if February 29th of a given year is a valid date. Very simple and shifts the burden onto VBA. I'd also like to suggest another test — if a given year has 366 days, it's also a leap year.
Public Function IsLeapYear(yr As Long) As Boolean
Const LEAP_YEAR_DAYS As Long = 366
Dim startYear As Date
Dim endYear As Date
startYear = CDate("1/1/" & yr)
endYear = CDate("1/1/" & (yr + 1))
' the difference between Jan 1st of the following year
' and the given year will be 366 in leap years
IsLeapYear = (endYear - startYear = LEAP_YEAR_DAYS)
End Function
Sample usage:
Sub TestLeapYear() Debug.Print IsLeapYear(1988) End Sub





Hey Jimmy -
Not sure if it affects your code or not, but … not every year divisible by 4 is a leap-year. Check out the official definition here: http://tinyurl.com/y9l7wfr
//ray
I'm kicking myself for not having thought to this!
This might be off topic, but I got curious and created these excel formulas.
Checks if February 29th of a given year is a valid date:
=MONTH(DATE(A1,2,29))=2 + ENTER
If a given year has 366 days:
=DATE(A1,12,31)-DATE(A2-1,12,31)=366 + ENTER
Perfect, thanks for sharing Oscar.
ps- I think you meant
=DATE(A1,12,31)-DATE(A1-1,12,31)=366
?
Yes, thanks!