Determine if it's a leap year

G

Guest

Hi all,
I need a piece of vba code to determine if it's a leap year.
Then I can add 29 days for the month of february.

Kind regards

Jan
 
B

Bob Phillips

Jan,

Here is one way, assuming your date is in A1

=IF(MONTH(DATE(YEAR(A1),2,29))=2,"Leap Year","Not a Leap Year")

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
N

Niek Otten

Hi Jan,

But are you sure you need this? In General, Excel will take care of dates
and the number of days in a month quite reliably.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel
 
T

Tom Ogilvy

Building on Bob's suggestion would be to determine the last day in February
(the zeroeth day in March)

in VBA
lyear = 2007
for i = 1 to day(dateSerial(lyear,3,0))

to demonstrate from the immediate window:

? day(dateserial(2008,3,0))
29
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Set Up Calendar To Account For Leap Years 2
Leap Year 7
need help with formula? 2
Date and Save As Questions 13
i need formula help 3
Determine if Leap Year 12
LEAP YEAR Validation 8
Error in Excel date calculations 3

Top