Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I perform a calculation on a 20 digit number in an excel ? | Excel Worksheet Functions | |||
Formula Help - Perform a calculation only if the result falls between 2 values | Excel Discussion (Misc queries) | |||
Using a Macro to perform a VLookup on varying number of rows | Excel Programming | |||
Perform functions on the result of adding two columns | Excel Worksheet Functions | |||
Using a macro to perform a TASK on another workbook | Excel Programming |