Results 1 to 4 of 4

Thread: Do you know when Easter is this year?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13

    Do you know when Easter is this year?

    Let me start by saying the code below is old, quite old for that matter. Back in the early 1980's, I came across a written algorithm for how to calculate when Easter falls for any given year. It was a word description for a series of calculations that would end up with the month and day for the given year that Easter falls on. So I decided back then to encode it into BASIC (the predecessor to VB). There were memory limitations back then, so the style was to use very short variable names (actually, there may have been a 2 significant character limit back then if I am remembering correctly). Being that so many years have passed, and the fact I have not seen the article the code was derived from for possibly 30 years now, the code still retains the one-character variable names I used originally.

    This function can be called either from your own VB code or used as a UDF (user defined function) directly inside a worksheet formula. When called from VB code, the minimum year value that can be passed in for its argument is 1583... has to do with when the Gregorian Calendar was first adopted, but know that 1583 was not the adoption date everywhere in the world, so if you plan to call this function with really early dates, you should verify the adoption date for the Gregorian Calendar in the locale you plan to use the function at. When called as a UDF, the function will correctly handle the 1904 date system if that is in-use on the computer the formula is calculate on (this is an addition to the code I was able to implement awhile ago) and the minimum year argument is 1900 for the standard date system and 1904 for the 1904 date system. Oh, I almost forgot, the maximum year argument for either date system is 9999.

    Code:
    Function Easter(ByVal YearIn As Integer) As Date
    
        Dim a As Long, b As Long, c As Long, d As Long, e As Long, f As Long, g As Long
        Dim h As Long, i As Long, k As Long, l As Long, m As Long, n As Long, p As Long
        Dim Adjustment1904 As Long
        
        If ActiveWorkbook.Date1904 Then Adjustment1904 = 1462
        
        If TypeName(Application.Caller) = "Range" Then
            If YearIn < 1900 - 4 * ActiveWorkbook.Date1904 Then
                Easter = CVErr(xlErrValue)
                Exit Function
            End If
        ElseIf YearIn < 1583 Then
            Err.Raise 5
        End If
    
        a = YearIn Mod 19
        b = YearIn \ 100
        c = YearIn Mod 100
        d = b \ 4
        e = b Mod 4
        f = (b + 8) \ 25
        g = (b - f + 1) \ 3
        h = (19 * a + b - d - g + 15) Mod 30
        i = c \ 4
        k = c Mod 4
        l = (32 + 2 * e + 2 * i - h - k) Mod 7
        m = (a + 11 * h + 22 * l) \ 451
        n = (h + l - 7 * m + 114) \ 31
        p = (h + l - 7 * m + 114) Mod 31
        
        Easter = DateSerial(YearIn, n, p + 1) - Adjustment1904
    
    End Function
    Last edited by DocAElstein; 07-11-2023 at 11:47 AM.

Similar Threads

  1. Test Copy Do you know when Easter is this year?
    By Rick Rothstein in forum Test Area
    Replies: 6
    Last Post: 08-01-2021, 08:23 PM
  2. Happy New Year
    By mahmoud-lee in forum Excel Help
    Replies: 7
    Last Post: 01-02-2014, 10:08 PM
  3. Happy New Year
    By mahmoud-lee in forum Greetings and Inception
    Replies: 7
    Last Post: 01-02-2014, 10:08 PM
  4. Arrange the data by year and format.
    By pesteness in forum Excel Help
    Replies: 15
    Last Post: 08-19-2012, 08:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •