Workdays in a date range with Saturday as a workday
I think I got it! See below. I just add (not subtract) 1 to the
startdate.
Function WorkDays(StartDate As Date, EndDate As Date) As Long
Dim D As Date
Dim NumWeeks As Long
NumWeeks = (EndDate - StartDate + 1) \ 7
WorkDays = NumWeeks * 6
For D = (StartDate + 1 + NumWeeks * 7) To EndDate
If Weekday(D) 1 Then WorkDays = WorkDays + 1
Next
End Function
I don't think adding 1 to the StartDate (as you show) is the way to go.
Won't this give you a count that is one too few for StartDates that are not
Sunday? Also, I think my function will miscount by one if the StartDate is a
Saturday. What I think you need is to add the 1 only if the StartDate is a
Sunday, and not for any other StartDate. That could be done by adding this
line as the last line of my function...
If WeekDay(StartDate) = 1 Then WorkDays = WorkDays + 1
Rick
|