Posted to microsoft.public.excel.worksheet.functions
|
|
How do I use the WORKDAY() for a 6days working wk excluding ho
Bob,
Thanks for your help, I used codes received from Bernie.
Have a nice day,
JP.F
"Bob Phillips" wrote:
This seems to work
Function DateAddSixDayWorkweek(ByVal StartDate As Date, _
WorkDays As Long, _
Holidays As Variant) As Date
Dim TheseHols As Variant
Dim DateAdded As Date
Dim mDays As Long
Dim HolsIndex As Long
Dim i As Long
If Weekday(StartDate) = 1 Then StartDate = StartDate - 1
DateAdded = DateAdd("d", 7 * (WorkDays \ 6) + _
(WorkDays Mod 6) - ((WorkDays Mod 6) _
7 - Weekday(StartDate)), StartDate)
If Not IsEmpty(Holidays) Then
ReDim TheseHols(LBound(Holidays) To UBound(Holidays))
HolsIndex = LBound(TheseHols)
For i = LBound(Holidays) To UBound(Holidays)
If Holidays(i) = StartDate And Holidays(i) <= DateAdded And _
Weekday(Holidays(i)) < 1 Then
mDays = mDays + 1
Else
TheseHols(HolsIndex) = Holidays(i)
HolsIndex = HolsIndex + 1
End If
Next i
End If
If mDays < 0 Then
If HolsIndex = LBound(Holidays) Then
TheseHols = Empty
Else
ReDim Preserve TheseHols(LBound(TheseHols) To HolsIndex - 1)
End If
DateAdded = DateAddSixDayWorkweek(DateAdded, mDays, TheseHols)
End If
DateAddSixDayWorkweek = DateAdded
End Function
--
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)
"JP.F" wrote in message
...
Could someone help me with below code from "Rick Rothstein (MVP - VB)"
where
holidays are excluded .
Many thanks,
JP.F
Function DateAddSixDayWorkweek(ByVal StartDate As Date, _
WorkDays As Long) As Date
If Weekday(StartDate) = 1 Then StartDate = StartDate - 1
DateAddSixDayWorkweek = DateAdd("d", 7 * (WorkDays \ 6) + _
(WorkDays Mod 6) - ((WorkDays Mod 6) _
7 - Weekday(StartDate)), StartDate)
End Function
|