See attached: VBA will need to be adjusted to your worksheet data format.
Function
=LEAVES(B3,C3)
Option Explicit
Function Leaves(StDate As Date, FnDate As Date) As Integer
Dim inArr() As Variant
Dim r As Long
Dim c As Long
Dim j As Long
Dim i As Long
Dim sr As Long
Dim fr As Long
Dim lSum As Integer
Dim n As Integer
Dim lastrow As Long
Dim lastcol As Long
Dim Start_date As Date
Dim inRng As Range
Dim ws1 As Worksheet
Dim lDates(1 To 740)
'
' Array with values of Leave dates (1=Leave Day)
'
For i = 1 To 740
lDates(i) = 0
Next i
Start_date = DateValue("January 01, 2015")
Set ws1 = Worksheets("Sheet1")
ws1.Activate
With ws1
lastrow = .Cells(Rows.Count, 5).End(xlUp).Row
lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
Set inRng = .Range(.Cells(3, 5), .Cells(lastrow, 6))
inArr = inRng
'
' Set "LDates" to 1 if date is non-weekend Leave date
'
For r = 1 To UBound(inArr, 1)
sr = inArr(r, 1)
fr = inArr(r, 2)
For j = sr To fr
n = Application.WorksheetFunction.Weekday(j, 2)
If n <= 5 Then
i = j - Start_date + 1
lDates(i) = 1
End If
Next j
Next r
lSum = 0
sr = StDate - Start_date + 1
fr = FnDate - Start_date + 1
For i = sr To fr
lSum = lSum + lDates(i)
Next i
End With
Leaves = lSum
End Function
Bookmarks