Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jan Jan is offline
external usenet poster
 
Posts: 159
Default Determine if it's a leap year

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Determine if it's a leap year

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)


"Jan" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Determine if it's a leap year

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

"Bob Phillips" wrote in message
...
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)


"Jan" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 634
Default Determine if it's a leap year

Unless of course, you start with a date in 1900 :-)

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------

"Bob Phillips" wrote in message
...
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)


"Jan" wrote in message
...
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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Determine if it's a leap year

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


--
Regards,
Tom Ogilvy


"Bob Phillips" wrote in message
...
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)


"Jan" wrote in message
...
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







  #6   Report Post  
Posted to microsoft.public.excel.programming
Jan Jan is offline
external usenet poster
 
Posts: 159
Default Determine if it's a leap year

Thanks, this was where what i'm looking for.

Jan

"Jan" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Leap Year BadBoy Excel Worksheet Functions 7 April 29th 09 11:49 PM
leap year p-nut Excel Discussion (Misc queries) 5 January 10th 08 05:34 AM
Leap Year Ralph Page Charts and Charting in Excel 3 November 5th 07 01:57 AM
How to determine if year is a leap year Wanda Excel Worksheet Functions 7 September 17th 07 07:48 AM
Leap Year scrabtree23[_2_] Excel Programming 3 December 8th 03 03:36 PM


All times are GMT +1. The time now is 03:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"