|
||||
Disse websidene oppdateres ikke lengre og er kun tilgjengelig for historikken sin skyld.Klikk her for å gå til den oppdaterte informasjonen. Beregn antall arbeidsdager innenfor et datointervallMed de egendefinerte funksjonene nedenfor kan man beregne antall arbeidsdager mellom to datoer. Arbeidsdager inkluderer vanlige ukedager unntatt lørdager og søndager, samt helligdager som f.eks. påsken. Funksjonene kan brukes slik i en regnearkcelle:
=CountWorkDays(A1,B1) =AddWorkDays(A1,15) =DateIsHoliday(A1) Dato input-cellene må inneholde gyldige Excel datoer eller formler/funksjoner som returnerer datoer, f.eks. =IDAG(). Function CountWorkDays(StartDate As Long, EndDate As Long) As Long
' returnerer antall arbeidsdager mellom de to angitte datoene
Dim d As Long, dCount As Long
dCount = 0
If StartDate < 1 Or EndDate < 1 Then Exit Function
If StartDate <= EndDate Then
For d = StartDate To EndDate
If Not DateIsHoliday(d) Then
dCount = dCount + 1
End If
Next d
Else
For d = StartDate To EndDate Step -1
If Not DateIsHoliday(d) Then
dCount = dCount + 1
End If
Next d
End If
CountWorkDays = dCount
End Function
Function AddWorkDays(StartDate As Long, Offset As Long) As Long
' returnerer en dato Offset dager fra StartDate
Dim d As Long, dCount As Long
If StartDate < 1 Then Exit Function
d = StartDate
If Abs(Offset) > 0 Then
dCount = 0
If Offset > 0 Then
Do
If Not DateIsHoliday(d) Then
dCount = dCount + 1
End If
d = d + 1
Loop Until dCount = Offset
d = d - 1
Else
Do
If Not DateIsHoliday(d) Then
dCount = dCount - 1
End If
d = d - 1
Loop Until dCount = Offset
d = d + 1
End If
End If
AddWorkDays = d
End Function
Function DateIsHoliday(InputDate As Long) As Boolean
' returnerer True dersom InputDate er en lørdag/søndag eller en annen helligdag
Dim d As Integer, intYear As Integer, lngEasterSunday As Long, OK As Boolean
OK = False
If InputDate > 0 Then
If Weekday(InputDate, vbMonday) >= 6 Then
OK = True
End If
If Not OK Then ' check if InputDate is a holiday
intYear = Year(InputDate)
d = (((255 - 11 * (intYear Mod 19)) - 21) Mod 30) + 21
lngEasterSunday = DateSerial(intYear, 3, 1) + d + (d > 48) + 6 - _
((intYear + intYear \ 4 + d + (d > 48) + 1) Mod 7)
OK = True
Select Case InputDate
Case CDate("1.1." & intYear) ' 1. Nyttårsdag
'Case lngEasterSunday - 4 ' Onsdag før påske
Case lngEasterSunday - 3 ' Skjærtorsdag
Case lngEasterSunday - 2 ' Langfredag
Case lngEasterSunday ' 1. Påskedag
Case lngEasterSunday + 1 ' 2. Påskedag
Case CDate("1.5." & intYear) ' 1. mai
Case CDate("17.5." & intYear) ' 17. mai
Case lngEasterSunday + 39 ' Kristi Himmelfartsdag
'Case lngEasterSunday + 48 ' Pinseaften
Case lngEasterSunday + 49 ' 1. Pinsedag
Case lngEasterSunday + 50 ' 2. Pinsedag
'Case CDate("24.12." & intYear) ' Julaften
Case CDate("25.12." & intYear) ' 1. Juledag
Case CDate("26.12." & intYear) ' 2. Juledag
'Case CDate("31.12." & intYear) ' Nyttårsaften
Case Else
OK = False
End Select
End If
End If
DateIsHoliday = OK
End Function
Dokumentet er sist oppdatert 2008-09-18 22:26:15 Utskriftsvennlig versjon
|
||||
| ||||