Leap Year Function

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Public Function IsLeapYear(ByVal SomeValue As Variant) _

As Boolean
On Error GoTo LocalError
Dim intYear As Integer
'The trick here is make sure that we get an integer
'The 3 Golden rules are:
'True if it is divisible by 4
'False if it is divisible by 100
'TRUE if it is divisble by 400
If IsDate(SomeValue) Then
intYear = CInt(Year(SomeValue))
Else
'try and get an integer from the parse
'does not matter if we get an error
'because the error trap will catch it
intYear = CInt(SomeValue)
End If
If TypeName(intYear) = "Integer" Then
IsLeapYear = ((intYear Mod 4 = 0) _
And (intYear Mod 100 <> 0) _
Or (intYear Mod 400 = 0))
End If
Exit Function
LocalError:
End Function

You might also like