Function GetWorkDays(ByVal StartDate As Long, ByVal EndDate As Long) As Long
' Returns the count of days between StartDate - EndDate minus Saturdays and Sundays
Dim d As Long, dCount As Long
For d = StartDate To EndDate
If Weekday(d, vbMonday) < 6 Then
dCount = dCount + 1
End If
Next d
GetWorkDays = dCount
End Function
Sub CalculateBusinessDays()
Dim MyCell As Range
For Each MyCell In Selection.Cells
If IsDate(MyCell.Value) And IsDate(MyCell.Offset(0, 1).Value) And IsEmpty(MyCell.Offset(0, 2)) Then
MyCell.Offset(0, 2).Value = GetWorkDays(MyCell.Value, MyCell.Offset(0, 1).Value)
End If
Next
End Sub
' Returns the count of days between StartDate - EndDate minus Saturdays and Sundays
Dim d As Long, dCount As Long
For d = StartDate To EndDate
If Weekday(d, vbMonday) < 6 Then
dCount = dCount + 1
End If
Next d
GetWorkDays = dCount
End Function
Sub CalculateBusinessDays()
'This module will Calculate Business Working Days between two Dates given in below format.
'ColA Col B ColC
'SDate eDate Result(Empty Cell)Dim MyCell As Range
For Each MyCell In Selection.Cells
If IsDate(MyCell.Value) And IsDate(MyCell.Offset(0, 1).Value) And IsEmpty(MyCell.Offset(0, 2)) Then
MyCell.Offset(0, 2).Value = GetWorkDays(MyCell.Value, MyCell.Offset(0, 1).Value)
End If
Next
End Sub
Comments