View Single Post
  #6   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Sat, 22 Jan 2005 07:45:02 -0800, rkk wrote:

I need one more argument in Networkdays function after Startdate and Enddate,
weekend day or days in form of 1,2,3,4,5,6,7 before holdays

Any solution

Thanx


Not possible to change the NetWorkdays function.

However, Domenic has given you a worksheet function solution. Here is a VBA
solution that allows you to define up to three weekend days (Sun=1; Sat = 7).
It can be easily modified if more weekend days are required.

To use this, <alt-F11 opens the VB Editor.
Ensure your project is highlighted in the Project Explorer window, then
Insert/Module and paste the code into the window that opens.

To use this, enter =NWrkDays(StartDate, EndDate) into some cell. The Holidays
must be represented by a range and the argument is optional, and must be left
blank if you will be defining weekend days. The weekend days are optional and
are entered as numbers. So a formula were the weekend was Sat, Sun and Mon and
where there were no holidays would be:

=NWrkDays(StartDate, EndDate,,1,2,7)


===========================
Function NWrkDays(StartDate As Date, EndDate As Date, _
Optional Holidays As Range = Nothing, _
Optional WeekendDay_1 As Integer = 0, _
Optional WeekendDay_2 As Integer = 0, _
Optional WeekendDay_3 As Integer = 0) As Long

Dim c As Range
Dim i As Long, j As Long
Dim Count As Long

For i = StartDate To EndDate
Count = Count + 1
Select Case Weekday(i)
Case WeekendDay_1, WeekendDay_2, WeekendDay_3
Count = Count - 1
Case Else
If Not Holidays Is Nothing Then
For Each c In Holidays
If i = c.Value Then
Count = Count - 1
Exit For
End If
Next c
End If
End Select
Next i

NWrkDays = Count
End Function
=============================
--ron