Networkdays in VBA

lucianot

Board Regular
Joined
Nov 5, 2005
Messages
83
I know there are several posts about this on the boards, but still can't get it to work:

My goal is to get the number of workdays between two dates in a VBA function. I tried simply using the Advanced Toolpak function NETWORKDAYS, but I get the error message "Sub or function not defined". I did reference to atpvbaen.xls in the Tools > References menu, so I don't know why Excel is not recognizing the function.

I used the following function to test it:

Function CalcNetDays(dInitial As Date, dEnd As Date)
CalcNetDays = NetworkDays(dInitial, dEnd)
End Function

Any reason the function is not working?
Also, I need to add the holidays to the function. The holidays are listed on a worksheet column. Do I simply add the range to the function, like below?

CalcNetDays = NetworkDays(dInitial, dEnd, Range("Holidays"))
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try the line:

CalcNetDays = Application.WorksheetFunction.NETWORKDAYS(dInitial,dEnd,A4:A6)

Where A4:A6 is your Holidays
 
Upvote 0
Assuming you've set the reference to atpvbaen.xls then try accessing the function like so:

Code:
CalcNetDays = [atpvbaen.xls].NetworkDays(dInitial, dEnd)

Jim, Networkdays is not a member of the WorksheetFunction class so I'm afraid what you've written won't work.
 
Upvote 0
I tried NateO's suggetion of using Application.Run but that didn't work either. If I use the original code, it says atpvbaen.xla is not found. If I change it to atpvbaen.xls, I get "Run method failed".
 
Upvote 0

Forum statistics

Threads
1,216,474
Messages
6,130,841
Members
449,598
Latest member
sunny_ksy

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