Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Perform a task if result is a whole number

I am trying to include some logic that will determine leap years. I
want to perform a given loop if the year is evenly divisible by 4. So,
if year/4 = a whole number, then do the loop.

What is the easiest way to accomplish this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Perform a task if result is a whole number

Public Function isLeapYear(yr As Integer) As Boolean
isLeapYear = False
If yr Mod 4 = 0 Then isLeapYear = True
End Function

wrote:
I am trying to include some logic that will determine leap years. I
want to perform a given loop if the year is evenly divisible by 4. So,
if year/4 = a whole number, then do the loop.

What is the easiest way to accomplish this?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Perform a task if result is a whole number

1900 is divisible by 4, but it's not a leap year. Same with 2100, 2200, 2300.
If the year is a century, it has to be divisible by 400.

You could rely on the way excel/VBA treats dates:

Function IsLeapYear(myYear As Long) As Boolean
if month(dateserial(myYear,2,29)) = 2 then
isLeapYear = true
else
IsLeapYear = false
end if
End Function

Excel and VBA are pretty smart when it comes to dates.

wrote:

I am trying to include some logic that will determine leap years. I
want to perform a given loop if the year is evenly divisible by 4. So,
if year/4 = a whole number, then do the loop.

What is the easiest way to accomplish this?


--

Dave Peterson
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
How do I perform a calculation on a 20 digit number in an excel ? vaishali Excel Worksheet Functions 1 September 9th 09 05:05 PM
Formula Help - Perform a calculation only if the result falls between 2 values Matt.Russett Excel Discussion (Misc queries) 4 June 11th 07 06:08 PM
Using a Macro to perform a VLookup on varying number of rows Shirley Munro[_3_] Excel Programming 1 September 5th 05 02:28 PM
Perform functions on the result of adding two columns Tim Archer Excel Worksheet Functions 2 February 2nd 05 03:25 PM
Using a macro to perform a TASK on another workbook JimKusche Excel Programming 1 October 2nd 03 02:11 PM


All times are GMT +1. The time now is 10:12 PM.

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

About Us

"It's about Microsoft Excel"