Friday, April 22, 2011

Happy Easter

Here is a quick and easy Excel VBA (Microsoft) user-defined function for determining the calendar date upon which Easter falls during any given year.

Public Function EasterDate(Yr As Integer) As Date
   Dim d As Integer
   d = (((255 - 11 * (Yr Mod 19)) - 21) Mod 30) + 21
   EasterDate = DateSerial(Yr, 3, 1) + d + (d > 48) + 6 - ((Yr + Yr \ 4 + d + (d > 48) + 1) Mod 7)
End Function

To find the date for Good Friday during any specific year, save the above code in your Excel VBA editor and then enter the function in an Excel worksheet. For example, =EasterDate(2011) returns 40657 which converts to 4/24/2011 when the cell is formated for dates. Likewise, =EasterDate(2011)-2 returns the date for Good Friday as 4/22/2011 (as in today).

Happy Easter!

No comments:

Post a Comment