Bernd,
I thought you might be interested in seeing this short one-liner alternative
to your "cwd" function (which requires your "min" function to operate); it
is fully self-contained and, as such, relies only on built-in VB
functions...
Function CWD(D1 As Date, D2 As Date) As Long
CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
(Weekday(D2) <> 7) + (Weekday(D1) = 1) + (Weekday(D1, 2) < 6)
End Function
Note that if you remove the last addend, that is the "+(Weekday(d1, 2)<6)"
logical expression, then the function will return the same results as
Excel's NETWORKDAYS function. If we provide the function with an Optional
parameter, we can make it return either result (yours or NETWORKDAYS's) like
so...
Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
(Weekday(D2) <> 7) + (Weekday(D1) = 1) - NWD * (Weekday(D1, 2) < 6)
End Function
The default for the NWD (short for NetWorkDays by the way) parameter is
False, meaning it returns the same results as does your "cwd" function...
pass True in for the NWD parameter and the function returns the same values
as Excel's NETWORKDAYS function.