Calculate Business Working Days between two dates (Excluding Saturdays and Sundays)

    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()
   '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
    End Sub


Jai said…
I am beginner , i didn't understand the concept of code,cos i have executed on vb but didn't get solution,so plz tell me the way to get solution