Hi Frank,
Yes, on re-reading I got that slant, If you want to include holiday lists
aka NETWORKDAYS I think this need VBA. Here is a routine I use
'---------------------------------------------------------------------
Function DaysBetween(StartDate, _
EndDate, _
Optional Holidays, _
Optional IncSat As Boolean = False, _
Optional IncSun As Boolean = False)
'---------------------------------------------------------------------
Dim cDays As Long
Dim StartDateWe As Date
Dim EndDateWE As Date
'check if valid arguments
If (Not IsDate(StartDate)) Then
GoTo DB_errValue_exit
ElseIf (Not IsDate(CDate(EndDate))) Then
GoTo DB_errValue_exit
ElseIf (StartDate > EndDate) Then
GoTo DB_errValue_exit
ElseIf (Not IsMissing(Holidays)) Then
If (TypeName(Holidays) <> "Range" And _
TypeName(Holidays) <> "String()" And _
TypeName(Holidays) <> "Variant()") Then
GoTo DB_errValue_exit
End If
End If
#If fDebug Then
Debug.Print StartDate & ", " & _
EndDate & ", " & _
IncSat & ", " & _
IncSun
#End If
cDays = EndDate - StartDate + 1
'determine the saturday after end date
EndDateWE = EndDate + (7 - Weekday(EndDate, vbSunday))
'reduce by appropriate no of saturdays
If Not IncSat Then
cDays = cDays - ((EndDateWE - StartDate) \ 7)
End If
'reduce by appropriate no of sundays
If Not IncSun Then
cDays = cDays - ((EndDateWE - StartDate) \ 7)
End If
'reduce by 1 if enddate is a saturday and saturdays not included
If Weekday(EndDate, vbSunday) = vbSaturday And Not IncSat Then
cDays = cDays - 1
End If
'reduce by 1 if startdate is a sunday and sundays not included
If Weekday(StartDate, vbSunday) = vbSunday And Not IncSun Then
cDays = cDays - 1
End If
'reduce by any holidays
If (Not IsMissing(Holidays)) Then
cDays = cDays - NumHolidays(StartDate, EndDate, Holidays, IncSat,
IncSun)
End If
DaysBetween = cDays
Exit Function
DB_errValue_exit:
DaysBetween = CVErr(xlErrValue)
End Function
'---------------------------------------------------------------------
Function NumHolidays(ByVal StartDate, _
ByVal EndDate, _
ByVal Holidays, _
ByVal IncSat As Boolean, _
ByVal IncSun As Boolean)
'---------------------------------------------------------------------
Dim cHolidays As Long
Dim cell
For Each cell In Holidays
If (IsDate(cell.Value)) Then
If (CDate(cell) >= StartDate And CDate(cell) <= EndDate) Then
cHolidays = cHolidays + 1
If (Weekday(CDate(cell), vbSunday) = vbSaturday) Then
If Not IncSat Then
cHolidays = cHolidays - 1
End If
ElseIf (Weekday(CDate(cell), vbSunday) = vbSunday) Then
If Not IncSun Then
cHolidays = cHolidays - 1
End If
End If
End If
End If
Next cell
NumHolidays = cHolidays
End Function
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)