I have found this code that will add working or business days to a date.
Is it possible to add to this code (so that I can just paste it into my module) to look up dates from a holiday table and add those as well ?
Code:
Public Function AddWeekdays(datDateIn As Date, intDays As Integer) As Date
' Comments: Add or subtract a number of weekdays to a date.
' Weekend dates are not counted in adding/subtracting days.
' Params : datDateIn Starting date
' intDays Number of days to add (negative to subtract)
' Returns : Original date plus the number of weekdays added
' Source : Total Visual SourceBook
On Error GoTo PROC_ERR
Dim intCounter As Integer
Dim intDirection As Integer
Dim datNewDate As Date
Dim lngWeeks As Long
Dim intDaysLeft As Integer
datNewDate = datDateIn
If intDays > 0 Then
intDirection = 1
Else
intDirection = -1
End If
lngWeeks = Fix(Abs(intDays) / 5)
If lngWeeks > 0 Then
datNewDate = datNewDate + lngWeeks * 7 * intDirection
End If
intDaysLeft = Abs(intDays) - lngWeeks * 5
For intCounter = 1 To intDaysLeft
datNewDate = datNewDate + 1 * intDirection
If intDirection > 0 Then
' Increment date
If Weekday(datNewDate) = 7 Then
datNewDate = datNewDate + 2
End If
Else
' Decrement date
If Weekday(datNewDate) = 1 Then
datNewDate = datNewDate - 2
End If
End If
Next intCounter
AddWeekdays = datNewDate
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.AddWeekdays"
Resume PROC_EXIT
End Function
Is it possible to add to this code (so that I can just paste it into my module) to look up dates from a holiday table and add those as well ?