NetworkDays with Dynamic Holiday Range

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I feel exceptionally dumb for not being able to figure this out, but here I am. I would like to make the holiday list a dynamic range so that when next year's holiday schedule is released by my company, I don't have to adjust the code; I can simply add the dates to the subject range. Here's what I've tried thus far"

VBA Code:
'Calculates the days to decision.
mHLR = mV.Range("P" & Rows.Count).End(xlUp).Row

HolidayList = mV.Range("P2:P" & mHLR).Value

'Returns a #NAME error
'mP.Range("AH2:AH" & mPLR).Value = "=NETWORKDAYS(RC[-20],RC[-15],HolidayList)"

'Returns a #VALUE error
'mP.Range("AH2:AH" & mPLR).Value = "=NETWORKDAYS(RC[-20]:RC[-15],Variables!C[-18])"

'Works, but isn't dynamic.
mP.Range("AH2:AH" & mPLR).FormulaR1C1 = "=NETWORKDAYS(RC[-20],RC[-15],Variables!R2C16:R12C16)-1"
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try
VBA Code:
'Calculates the days to decision.
Dim HolidayList as Range
mHLR = mV.Range("P" & Rows.Count).End(xlUp).Row

Set HolidayList = mV.Range("P2:P" & mHLR)


mP.Range("AH2:AH" & mPLR).Value = "=NETWORKDAYS(RC[-20],RC[-15]," & HolidayList & ")"
 
Upvote 0
Try
VBA Code:
'Calculates the days to decision.
Dim HolidayList as Range
mHLR = mV.Range("P" & Rows.Count).End(xlUp).Row

Set HolidayList = mV.Range("P2:P" & mHLR)


mP.Range("AH2:AH" & mPLR).Value = "=NETWORKDAYS(RC[-20],RC[-15]," & HolidayList & ")"
@Fluff thank you for the prompt response. I'm utilizing your suggestion, but getting a Type Mismatch error.
 
Upvote 0
Ok, how about
Excel Formula:
mP.Range("AH2:AH" & mPLR).formular1c1= "=NETWORKDAYS(RC[-20],RC[-15]," & HolidayList.Address(, , xlR1C1) & ")"
 
Upvote 0
Ok, how about
Excel Formula:
mP.Range("AH2:AH" & mPLR).formular1c1= "=NETWORKDAYS(RC[-20],RC[-15]," & HolidayList.Address(, , xlR1C1) & ")"
I copy and pasted your suggestion into the code. The formula it places leavels out the worksheet reference.

Excel Formula:
=NETWORKDAYS(N3,S3,$P$2:$P$12)
 
Upvote 0
In that case use
VBA Code:
HolidayList.Address(, , xlR1C1, 1)
 
Upvote 0
Solution
In that case use
VBA Code:
HolidayList.Address(, , xlR1C1, 1)
Ok, that worked. If you would, help me understand what these sections mean:

I assume
VBA Code:
HolidayList.Address
puts the range I set earlier in the formula. I have no idea what this is
VBA Code:
 (, , xlR1C1, 1)
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,601
Members
449,109
Latest member
Sebas8956

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