Function Networkdaysvba(startDate As Double, endDate As Date, Optional holidays As Variant) As Integer
Dim i As Integer
Dim tmp As Integer
Dim dt As Date, dtStart As Date
startDate = Fix(startDate)
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
Function EOMonthVBA(startDate As Double, months As Long) As Date
startDate = Fix(startDate)
EOMonthVBA = DateAdd("m", months + 1, startDate - Day(startDate) + 1) - 1
End Function
Function EDateVBA(startDate As Double, months As Long) As Date
startDate = Fix(startDate)
EDateVBA = DateAdd("m", months, startDate)
End Function
|