I am using the workday function to build a schedule. This function
counts the workweek as Monday thru Friday, but I'm working with a
Monday thru Saturday workweek. Is there any way to adjust the
function? Or maybe there is anther type of workaround?
From a previous post of mine....
Here is a function I have posted in the compiled VB newsgroups (modified for
your requirement that Saturday is a workday) which calculates the number of
workdays (Monday thru Saturday) between any two dates, but it does not
account for Holidays (which vary by countries and, within the US, even by
individual states)...
Function WorkDays(StartDate As Date, EndDate As Date) As Long
Dim D As Date
Dim NumWeeks As Long
NumWeeks = (EndDate - StartDate) \ 7
WorkDays = NumWeeks * 6
For D = (StartDate + NumWeeks * 7) To EndDate
If Weekday(D) > 1 Then WorkDays = WorkDays + 1
Next
End Function
It is fast because the maximum number of iteration in the loop is 6. The
holidays part of your question will have to be dealt with using a separate
loop. I would probably store the Holidays (within some maximum range of
dates) in an array and loop the array seeing if the individual Holiday dates
falls within, or on, the span covered by StartDate and EndDate and subtract
one for each date doing so.
Rick