Networdays

Dave Bonallack

New Member
Joined
Mar 23, 2014
Messages
2
Hi,
I have 2 lists of dates that I want to enter into the Networkdays function.
The first is a list of public holidays and factory-closed dates that are common to all employees.
The second is a list specific to each employee, holding that employee's booked leave dates.
I found a thread that suggested using NETWORKDAYS twice, then doing some math on the 2 results, but that produced errors if there were duplicates in the 2 lists.
For example:
Here in Australia we have a national holiday on April 25, so that date will occur in the common list.
John Smith wants 2 weeks off from April 21 thru May 2, so those dates get entered into John's personal list.
When I use NETWORKDAYS on each list, April 25 gets considered twice, which results in an error.

So, how can I ask NETWORKDAYS to consider 2 lists of dates, and not get errors when the same date appears in both lists?

Regards - Dave Bonallack
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Add the following code to your workbook, using Alt+F11...

Function ArrayUnion(ParamArray Arg() As Variant) As Variant
' Code: Juan Pablo González
' Spec: Aladin Akyurek
' May 4, 2003
' Ref: TinyURL.com - shorten that long URL into a tiny URL
Dim TempUnion() As Variant
Dim i As Long, Itm As Variant, Ctr As Long
For i = LBound(Arg) To UBound(Arg)
Arg(i) = Arg(i)
If IsArray(Arg(i)) Then
For Each Itm In Arg(i)
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Itm
Next Itm
Else
Ctr = Ctr + 1
ReDim Preserve TempUnion(1 To Ctr) As Variant
TempUnion(Ctr) = Arg(i)
End If
Next i
ArrayUnion = TempUnion
End Function

Now you can invoke:

=NETWORKDAYS(date1,date2,ARRAYUNION(CommonList,IndividualList))
 
Upvote 0
Thanks Aladin. That works great! Gives me much more flexibility than I had before.
The UDF seems to create a union of the two ranges. Even though the new (unionized) range contains duplicates, NETWORDAYS ignores for them.
As a matter of interest, I tried that with just with the standard spreadsheet function, putting duplicates in the holiday dates list. NETWORDAYS ignores them there too.
Very good solution. Thanks again.
Dave.
 
Upvote 0
Thanks Aladin. That works great! Gives me much more flexibility than I had before.

You are welcome.

The UDF seems to create a union of the two ranges. Even though the new (unionized) range contains duplicates, NETWORDAYS ignores for them.

Yep.

As a matter of interest, I tried that with just with the standard spreadsheet function, putting duplicates in the holiday dates list. NETWORDAYS ignores them there too.
Very good solution. Thanks again.
Dave.

Good thinking. I tested that too and observed that result when I thought of ARRAYUNION. Thanks for the explanatory feedback.
 
Upvote 0

Forum statistics

Threads
1,215,450
Messages
6,124,912
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top