Results 1 to 7 of 7

Thread: Test Copy 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
    662
    Rep Power
    13

    Test Copy 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

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9iHOYYpaA bC
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgxuL6YCUckeUIh9hoh4AaABAg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwGTEyefOX7msIh1wZ4AaABAg.9h4sd6Vs4qE9h7G-bVm8_-
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=Ugw3nF0C04AGt73H1BB4AaABAg.9h6VhNCM-DZ9h7EqbG23kg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwGTEyefOX7msIh1wZ4AaABAg.9h4sd6Vs4qE9h7KvJXmK 8o
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=Ugw3nF0C04AGt73H1BB4AaABAg.9h6VhNCM-DZ9h7E1gwg4Aq
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgywFtBEpkHDuK55r214AaABAg
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg.9h5lFRmix1R9h79hNGvJ bu
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg.9h5lFRmix1R9h79YAfa2 4T
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg.9h5lFRmix1R9h79M1SYH 1E
    https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg.9h5lFRmix1R9h78SxhXT nR
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwhVTFaD469mW9wO194AaABAg.9gJzxwFcnPU9gORqKw5t W_
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugyb8nmKKoXvcdM58gV4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgwvvXcl1oa79xS7BAV4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgxvIFArksPprylHXYZ4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 07-11-2023 at 12:41 PM.

Similar Threads

  1. Replies: 17
    Last Post: 12-18-2012, 04:15 PM
  2. Arrange the data by year and format.
    By pesteness in forum Excel Help
    Replies: 15
    Last Post: 08-19-2012, 08:54 PM
  3. Merry Christmas and Happy New Year
    By Admin in forum Greetings and Inception
    Replies: 1
    Last Post: 01-02-2012, 12: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
  •