Hi there,
Many thanks for that very clear description of your requirements.
Take a look at the attached workbook and see if it does what you need. I have rewritten your "HelligdagsNavn" routine as follows:
Function HelligdagsNavn(lngdate As Long, InclSaturdays As Boolean, _
InclSundays As Boolean, Optional sYesNo As String) As String
' Returnerer Sand hvis lngDate er en Dansk HelligdagsNavn/nationaldag
' (valgfri inkludering af lordag/sondag)
' bruger funktionen Paskedag
Dim InputYear As Integer, PD As Long ' <<< The "OK" variable is not used
If lngdate <= 0 Then
lngdate = Date
End If
InputYear = Year(lngdate)
PD = Paskedag(InputYear)
Select Case lngdate ' Tester nedenstaende pastande mod datoen
Case DateSerial(InputYear, 1, 1): HelligdagsNavn = "Nytarsdag"
Case PD - 3: HelligdagsNavn = "Skaertorsdag"
Case PD - 2: HelligdagsNavn = "Langfredag"
Case PD: HelligdagsNavn = "Paskedag"
Case PD + 1: HelligdagsNavn = "2. Paskedag"
Case PD + 26: HelligdagsNavn = "Store Bededag"
Case PD + 39: HelligdagsNavn = "Kr. Himmelfartsdag"
Case PD + 49: HelligdagsNavn = "Pinsedag"
Case PD + 50: HelligdagsNavn = "2. Pinsedag"
Case DateSerial(InputYear, 12, 24): HelligdagsNavn = "Julaftensdag"
Case DateSerial(InputYear, 12, 25): HelligdagsNavn = "1. Juledag"
Case DateSerial(InputYear, 12, 26): HelligdagsNavn = "2. Juledag"
Case DateSerial(InputYear, 12, 31): HelligdagsNavn = "Nytarsaftensdag"
Case DateSerial(InputYear, 6, 5): HelligdagsNavn = "Grundlovsdag"
Case DateSerial(InputYear, 5, 1): HelligdagsNavn = "1. Maj"
If UCase(sYesNo) = "YES" Then
HelligdagsNavn = "1. Maj"
Else: HelligdagsNavn = ""
End If
Case Else
End Select
If InclSaturdays Then ' Tester lordage, hvis de skal medtages
If Weekday(lngdate, vbMonday) = 6 Then
HelligdagsNavn = HelligdagsNavn & " Lordag"
End If
End If
If InclSundays Then ' Tester sondage, hvis de skal medtages
If Weekday(lngdate, vbMonday) = 7 Then
HelligdagsNavn = HelligdagsNavn & " Sondag"
End If
End If
End Function
The optional argument "sYesNo" is used only in Cell B4 (for the date of 1 May yyyy) as follows:
=HelligdagsNavn(A4, 0, 0, D10)
where D10 is the cell which contains the Yes / No value
For all other cells the function is entered without the optional argument, e.g.
=HelligdagsNavn(A5, 0, 0)
As far as I can tell, it's not really necessary to include your error handling when the function is used, i.e.
=IFERROR(IF(A5="","",HelligdagsNavn(A5,0,0)),"")
Please note that in order to get the site to accept this post I have had to use the highlighted "English" letters as replacements for the original Danish ones - the attached workbook contains the Danish characters copied from your workbook.
Hope this helps - please let me know how you get on.
Regards,
Greg M
Bookmarks