Link to home
Start Free TrialLog in
Avatar of DougDodge
DougDodge

asked on

Excel VBA to calculate observed Boxing Day Holiday

Looking for a VBA script of code to calculate both the observed Christmas and Boxing days.
If Christmas falls on a Friday, then Boxing Day would be observed as Monday, December 28
If Christmas falls on a Saturday, then observed holiday is December 24, and Boxing Day would be Sunday and observed as Monday December 27
If Christmas falls on a Sunday, then Christmas is observed as Monday December 26, and Boxing Day moves to Tuesday December 27
Avatar of Rgonzo1971
Rgonzo1971

HI,

pls try

Function ObservedBoxingDay(thedate As Date) As Date
dtXmas = DateValue("25/12/" & Year(thedate))
If dtXmas Mod 7 = 1 Then
    res = WorksheetFunction.WorkDay(dtXmas, 2)
Else
    res = WorksheetFunction.WorkDay(dtXmas, 1)
End If
ObservedBoxingDay = res

End Function
Function ObservedXmasDay(thedate As Date) As Date
dtXmas = DateValue("25/12/" & Year(thedate))
If dtXmas Mod 7 = 1 Then
    res = WorksheetFunction.WorkDay(dtXmas, 1)
Else 
    res = dtXmas
End If
ObservedXmasDay = res

End Function

Open in new window

Regards
ASKER CERTIFIED SOLUTION
Avatar of DougDodge
DougDodge

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DougDodge

ASKER

The presented solution had errors when run. It did not properly dim the variables.