ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Work out Days Between Two Dates (https://www.excelbanter.com/excel-programming/349681-work-out-days-between-two-dates.html)

vqthomf

Work out Days Between Two Dates
 
Hi Is there a way to workout days between two dates like networkdays in code.
any help will be much appreciated
Charles

Peter Beach

Work out Days Between Two Dates
 
Hi Charles,

One way:

Sub a()
Dim x As Long
Dim d1 As Long, d2 As Long
d1 = DateSerial(2000, 1, 1)
d2 = DateSerial(2002, 1, 1)
x = Application.Evaluate("=NETWORKDAYS(" & d1 & "," & d2 & ")")
Debug.Print x
End Sub

HTH

Peter Beach

"vqthomf" wrote in message
...
Hi Is there a way to workout days between two dates like networkdays in

code.
any help will be much appreciated
Charles




Ron Rosenfeld

Work out Days Between Two Dates
 
On Fri, 6 Jan 2006 21:16:14 +1300, "Peter Beach" wrote:

Hi Charles,

One way:

Sub a()
Dim x As Long
Dim d1 As Long, d2 As Long
d1 = DateSerial(2000, 1, 1)
d2 = DateSerial(2002, 1, 1)
x = Application.Evaluate("=NETWORKDAYS(" & d1 & "," & d2 & ")")
Debug.Print x
End Sub

HTH


or, if you set a reference to atpvbaen.xls:

Sub a()
Dim x As Long
Dim d1 As Long, d2 As Long
d1 = DateSerial(2000, 1, 1)
d2 = DateSerial(2002, 1, 1)
x = NETWORKDAYS(d1, d2)
Debug.Print x
End Sub



--ron


All times are GMT +1. The time now is 11:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com