# Thread: Finding a Leap Year in VBA.

1. Registered User
Join Date
Feb 2004
Posts
47

## Unanswered: Finding a Leap Year in VBA.

Hi,

I have got a String strMMYY = "2003/04" for a financial year.

I would like to turn the string to an integer 2004 and check out if it is a leap year.

Can someone help with VBA code for this?

Regards

2. Registered User
Join Date
Feb 2004
Posts
142
if year mod 4 = 0 then leap year

3. Registered User
Join Date
Feb 2004
Posts
142

## Re: Finding a Leap Year in VBA.

Originally posted by Kashizzz
Hi,

I have got a String strMMYY = "2003/04" for a financial year.

I would like to turn the string to an integer 2004 and check out if it is a leap year.

Can someone help with VBA code for this?

Regards
if the string is always like this then you can do a mid function
intYear = cint("20" & mid(strMMYY,6))

4. Registered User
Join Date
Feb 2004
Location
Chicago, IL
Posts
1,312
If you are using the calculation for recent years then the equation above will work. But if you were going back a couple hundred years or forward a couple hundred years then you would need something else.

1. Years divisible by four are leap years, unless...
2. Years also divisible by 100 are not leap years, except...
3. Years divisible by 400 are leap years.

5. Stuck on my opinions...
Join Date
Nov 2003
Posts
1,487
Code:
```'Check to see is this is a Leap Year
Dim Date1 As Date, Date2 As Date, IsLeapYear As Boolean
Date1 = "January 1," & Year(Now()): Date2 = "December 31," & Year(Now())
If DateDiff("d", Date1, Date2) = 365 Then
IsLeapYear = True
MsgBox " This is a Leap Year"
End if```
There ya go...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•