Function Networkdaysvba(startDate As Date, endDate As Date, Optional holidays As Variant) As Integer
Dim i As Integer
Dim tmp As Integer
Dim dt As Date, dtStart As Date
tmp = ((endDate - startDate + 1) \ 7) * 5 ' entire work weeks
dtStart = startDate + (tmp * 7 / 5) ' move to last week
For dt = dtStart To endDate
If Weekday(dt, vbMonday) <= 5 Then tmp = tmp + 1 ' add work days in the last week
Next
If IsArray(holidays) Then
For Each h In holidays
' if any holiday falls in the range, remove it
If Weekday(h, vbMonday) <= 5 And _
startDate <= h And endDate >= h Then
tmp = tmp - 1
End If
Next
End If
Networkdaysvba = tmp
End Function
|