NETWORKDAYS Function in Macro

  • Thread starter Thread starter Ken
  • Start date Start date
K

Ken

If we have dates in A1 and A2, we can use the NETWORKDAYS
function in Excel to get a net workday count.
=NETWORKDAYS(A1,A2)

Is there a way to get this result in a macro?

TIA.
 
Set a reference to the Analysis toolpak, APTVBAEN.XLA (lower-case on my
machine) and then just call it, like so

?networkdays(date-100,date-10)
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Sorry, Bob, but you lost me here.
How/where do we set a reference to the Analysis toolpak?
What goes into the macro code?
Thanks for your patience.
 
Ken,

In Excel, go to the Tools menu, choose Add-Ins, and the put a
check next to "Analysis Tool Pak - VBA". Then, go the VBA
editor, choose the Tools menu, then References. There, put a
check next to "ATPVBAEN.XLA".


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
So, with dates in A1 and A2 would the code to put the
networkdays in A3 be:

Sub Test()
Dim count As Integer
wks.Cells(3, 1).Value = networkdays(A2, A1)
End Sub

I am coding it wrong because it doesn't seem to work?
 
Ken,

Use

wks.Cells(3, 1).Value = networkdays(Range("A2"),Range("A1"))


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
or you could use

Application.Evaluate("NETWORKDAYS(A2,A1)")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Did you set the reference as described?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Yes, although my reference is atpvbaen.xls not
atpvbaen.xla.

Anyway, I entered the following code and got it to work.

Sub Test()
Dim count As Integer
count = Application.Evaluate("NETWORKDAYS(A2,A1)")
Range("A3").Select
ActiveCell.Value = count
End Sub
 
You are right, so is mine. Mine works though<G>

Sorry no other ideas at the moment. Have you tried my Evaluate suggestion,
it shouldn't make any difference but you never know.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top