A Conversation for Calculating the Date of Easter

MS Office Macro

Post 1

Geoff Taylor - Gullible Chump

Based entirely on Gnomon's work, you can cut & paste the following into an MS Excel macro module as a functioning macro...

Sub Easter()
' Courtesy of GNOMON, A H2G2 Researcher - Dec 2001
' http://www.bbc.co.uk/h2g2/guide/A653267
' Given the Year as a four digit number in the range 1700 - 2299
' Calculate Day and Month of Easter Sunday

' Note 1: the algorithm has not been tested outside this range.
' Note 2: the \ operator performs integer division without remainder.
' Note 3: the date returned is the Gregorian Calendar date
' (the one we use now), even for dates in the 18th Century.
Dim a, b, c, d, e, f, g, h, i, j, k, m, n, Month, Day
Dim Year
Year = InputBox("Enter the Year (yyyy) and the date of Easter Sunday will be calculated")

a = Year Mod 19
b = Year \ 100
c = Year Mod 100
d = b \ 4
e = b Mod 4
f = c \ 4
g = c Mod 4

h = (b + 8 ) \ 25
i = (b - h + 1) \ 3
j = (19 * a + b - d - i + 15) Mod 30
k = (32 + 2 * e + 2 * f - j - g) Mod 7
m = (a + 11 * j + 22 * k) \ 451
n = j + k - 7 * m + 114

Month = n \ 31
Day = (n Mod 31) + 1

MsgBox ("Day " & Day & " of Month " & Month)
End Sub


I hope this is useful to someone.. it is to me.

Thanks GNOMON smiley - cheers

Geoff Taylor


MS Office Macro

Post 2

Geoff Taylor - Gullible Chump

Argh... Smiley alert!!!

I cut and pasted my code into my entry, and H2G2 decided to recognise the bigeyes smiley. When you paste this into Excel, the smiley will be ignored. You will need to manually type an "8" and an ")" in its place.

I'll contact TPTB and see if they can kill the smiley, but until then....


MS Office Macro

Post 3

Gnomon - time to move on

You could just put a space between the 8 and the ).


MS Office Macro

Post 4

Geoff Taylor - Gullible Chump

Yeah, I could...

The point is I didn't smiley - smiley

Silly sod that I am.


MS Office Macro

Post 5

Peta

I've put a space in the posting above. That worked. smiley - smiley All fixed now!


MS Office Macro

Post 6

Lakeman

I got bored and thought I'd mess around with the macro.

Thanks Gnomon and Geoff Taylor has left the building.



Sub Easter version2()
' Courtesy of GNOMON, A H2G2 Researcher - Dec 2001
' http://www.bbc.co.uk/h2g2/guide/A653267
' http://www.bbc.co.uk/h2g2/alabaster/U185857
' Given the Year as a four digit number in the range 1700 - 2299
' Calculate Day and Month of Easter Sunday

' Note 1: the algorithm has not been tested outside this range.
' Note 2: the \ operator performs integer division without remainder.
' Note 3: the date returned is the Gregorian Calendar date
' (the one we use now), even for dates in the 18th Century.
Dim a, b, c, d, e, f, g, h, i, j, k, m, n, Month, Month1, Day, Suffix, TodaysDate, DateInQuestion
Dim Year
Year = InputBox("Enter the Year (yyyy) and the date of Easter Sunday will be calculated")

If Year < 1700 Then GoTo Line3
If Year > 2299 Then GoTo Line2 Else GoTo Line1


Line1:
a = Year Mod 19
b = Year \ 100
c = Year Mod 100
d = b \ 4
e = b Mod 4
f = c \ 4
g = c Mod 4

h = (b + 8) \ 25
i = (b - h + 1) \ 3
j = (19 * a + b - d - i + 15) Mod 30
k = (32 + 2 * e + 2 * f - j - g) Mod 7
m = (a + 11 * j + 22 * k) \ 451
n = j + k - 7 * m + 114

Month = n \ 31
Day = (n Mod 31) + 1



If Month = 3 Then Month1 = "March"
If Month = 4 Then Month1 = "April"

Suffix = "th" 'initialise variable

If Day = 1 Then Suffix = "st"
If Day = 21 Then Suffix = "st"
If Day = 31 Then Suffix = "st"
If Day = 2 Then Suffix = "nd"
If Day = 22 Then Suffix = "nd"
If Day = 3 Then Suffix = "rd"
If Day = 23 Then Suffix = "rd"



If Year < 2003 Then GoTo LineA Else GoTo LineB 'for dates in the past or future

LineA:
MsgBox ("Easter Sunday in " & Year & " was on the " & Day & Suffix & " of " & Month1)
GoTo LineC 'dates in the past

If Year > 2003 Then GoTo LineB
LineB:
MsgBox ("Easter Sunday in " & Year & " will be on the " & Day & Suffix & " of " & Month1)
GoTo LineC 'dates in the future

LineC:
MsgBox ("Thanks for taking an interest in Christianity. For more information visit your local church.")

GoTo Line4

Line2:
MsgBox ("Sorry, the year cannot be after 2299")
GoTo Line4

Line3:
MsgBox ("Sorry, the year cannot be before 1700")

Line4:
End Sub


MS Office Macro

Post 7

Gnomon - time to move on

Line C: smiley - biggrin

smiley - ok


MS Office Macro

Post 8

Geoff Taylor - Gullible Chump

Sssh... I'm making a principled stand at the moment and I'm not supposed to be posting to H2G2, but...

I like the added bells and whistles, and line C is a hoot. smiley - smiley However, you've hard-coded 2003 into your calculation. You can get the current year like this...

dim Thisyear
Thisyear = year(now)

If I'm telling granny to suck eggs then please ignore me!

smiley - cheers
Geoff


MS Office Macro

Post 9

Lakeman

That's great! I thought for ages about how to get the current year, but I couldn't figure it out. It was getting all complicated using dd/mm/yyyy and I decided to give up. Thanks.


Key: Complain about this post