"n" unique random dates between date range, excluding weekends and a list of public holidays

mafallaize

New Member
Joined
Aug 23, 2011
Messages
31
Hi all,

This problem has had me stumped for a while now. I'm looking for a formula to produce unique random dates between a date range, excluding weekends and a list of public holidays (different for each year). Like a lottery, once a date has been selected, it shouldn't be used again.

My sheet looks like this:
Sampling start date
Sampling end date
1
2
3
4
5
01/10/2017
01/01/2018
01/01/2018
01/04/2018
01/04/2018
01/07/2018
01/07/2018
01/10/2018

<tbody>
</tbody>

NETWORKDAYS works well for all of the above requirements, except it creates duplicates.

The Lottery style UDF posted by Jon von der Heyden here could be useful, but I couldn't get it to exclude weekends: https://www.mrexcel.com/forum/excel-questions/638342-formulae-help-please.html

Any ideas would be appreciated!

Thanks
Mark
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
It can be done in a rather longish complicated formula:

Excel 2012
ABCDEFGH
1Sampling start dateSampling end date12345
21/10/20171/1/20188/22/20177/11/20172/14/20171/19/20171/24/2017
31/1/20181/4/20181/1/20181/4/20181/2/20181/3/2018#NUM!
41/4/20181/7/20181/4/20181/5/2018#NUM!#NUM!#NUM!
51/7/20181/10/20181/8/20181/10/20181/9/2018#NUM!#NUM!
6
7
8
9Holidays
102/19/2018
117/3/2018
1211/11/2018

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet2

Array Formulas
CellFormula
D2{=LARGE(IF(WEEKDAY(ROW(INDIRECT($A2&":"&$B2)),2)<6,IF(ISERROR(MATCH(ROW(INDIRECT($A2&":"&$B2)),$A$10:$A$12,0)),IF(ISERROR(MATCH(ROW(INDIRECT($A2&":"&$B2)),$C2:C2,0)),ROW(INDIRECT($A2&":"&$B2))))),RANDBETWEEN(1,NETWORKDAYS($A2,$B2,$A$10:$A$12)-COLUMNS($D2:D2)+1))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0
Glad to help! :cool:

FWIW, here's a slightly shorter version:

Code:
=LARGE(IF(WORKDAY(ROW(INDIRECT($A2&":"&$B2))-1,1,$A$10:$A$12)=ROW(INDIRECT($A2&":"&$B2)),IF(ISERROR(MATCH(ROW(INDIRECT($A2&":"&$B2)),$C2:C2,0)),ROW(INDIRECT($A2&":"&$B2)))),RANDBETWEEN(1,NETWORKDAYS($A2,$B2,$A$10:$A$12)-COLUMNS($D2:D2)+1))
 
Upvote 0
Concise is nice! I've used your shorter version. The complexity in this nested formula is remarkable to me.

Thanks again! :D
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

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