- Home
·
- Miscellaneous
·
- Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function
Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function
Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function (eg October 1 to October 31 will output 23
Rate Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function
(1(1 Vote))
Dim FDate As Date
Dim SDate As Date
Dim DaysApart As Integer
Dim Weekends As Integer
DaysApart = 0
Weekends = 0
' this function will show the amount of business days including start date e.g. Oct 1 to Oct 31
' will display 23 business days (works along the same lines as Excel's 'networkdays' function)
FDate = FirstDate
SDate = SecondDate
If SDate < FDate Then
MsgBox "Second date is less than first date.", vbCritical, "Error..." ' second date is less than first date
Exit Function
End If
DaysApart = DateDiff("d", FDate, SDate) + 1 ' + 1 is to include start date
Do Until FDate = SDate
FDate = FDate + 1 ' will loop until dates match
If Format(FDate, "dddd") = "Saturday" Or Format(FDate, "dddd") = "Sunday" Then
Weekends = Weekends + 1 ' checks day and if Sat or Sun, then adds 1
End If
Loop
If Format(FirstDate, "dddd") = "Saturday" Or Format(FirstDate, "dddd") = "Sunday" Then
Weekends = Weekends + 1 ' if start date is weekend day then add one
End If
FindBusDays = DaysApart - Weekends
End Function
Finds business days between two dates. Works along the same lines as Excel's 'networkdays' function Comments
No comments yet — be the first to post one!
Post a Comment