View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
merjet merjet is offline
external usenet poster
 
Posts: 812
Default Count difference in days input box

A brute force method would loop day-by-day counting the number of
days, Saturdays and Sundays. The Weekday function, available in VBA,
can tell which days are Saturdays and Sundays.

Another route is to use the NetWorkDays worksheet formula.
Unfortunately this is not available in VBA, so you'd have to put the
start date, end date, and NetWorkDays formula on a worksheet somwhere
and then capture its result in VBA. Note: Networkdays counts both the
start day and end day!

Suppose iDays is the numbers days between two dates, counting both the
start and end days, i.e. 1+Int(EndDate-StartDate). iWkDays is the same
excluding Saturdays and Sundays. Then if iDays - iWkDays is even, the
number of days excluding Saturdays is 0.5*(iDays + iWkDays). If iDays
- iWkDays is odd:
(a) if the earliest day isn't a Sunday, the number of days excluding
Saturdays is 0.5*(iDays + iWkDays) - 0.5,
(b) if the earliest day is a Sunday, the number of days excluding
Saturdays is 0.5*(iDays + iWkDays) + 0.5.

A nice thing about using the NetWorkDays formula is it can exclude
holidays as well. See Excel's Help for the formula.

Hth,
Merjet