calculate number of days formula
You are quite welcome... it was a fun "challenge" even though you didn't
present your posting as a challenge.
--
Rick (MVP - Excel)
"Bernd P" wrote in message
...
Hello Rick,
Great. Tested and published as well. No need anymore for my cwd
version. Thanks.
Regards,
Bernd
On 25 Apr., 21:15, "Rick Rothstein"
wrote:
Sorry, it looks like I implemented the NWD parameter backwards. This
should
produce the correct results for the NWD parameter equaling True and
False...
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) - (Not NWD) * (Weekday(D1, 2) < 6)
End Function
And here it is with the renamed parameters to enforce the requirement
that
D1 must be the earlier date and D2 the later one...
Function CWD(StartDate As Date, EndDate As Date, _
Optional NWD As Boolean) As Long
CWD = DateDiff("d", StartDate, EndDate) - DateDiff("ww", StartDate, _
EndDate) * 2 - (Weekday(EndDate) < 7) + (Weekday(StartDate) = 1)
_
- (Not NWD) * (Weekday(StartDate, 2) < 6)
End Function
--
Rick (MVP - Excel)
|