Need some help to figure this out. It is basically the opposite of networkdays, my UDF will count how many days in a date range are weekend days and holidays.
Need some suggestions to help me get this to work.
Thanks
Code:
Public Function NonWorkDays(StartDate As Date, EndDate As Date) As Long
Dim wb As Workbook
Dim wsList As Worksheet
Dim ListLR As Long, x As Long
Set wb = ThisWorkbook
Set wsList = wb.Sheets("HolidayList")
ListLR = wsList.Cells(wsList.Rows.Count, 4).End(xlUp).row
DayCount = 0
For i = StartDate To EndDate
'find weekends
D = Weekday(i) '// 1 = Sunday, 7 = Saturday
If D = 1 Or D = 7 Then
'count the day
DayCount = DayCount + 1
End If
For x = 2 To ListLR
If wsList.Cells(x, 4) = i Then
'count the day
DayCount = DayCount + 1
End If
Next x
Next i
NonWorkDays = DayCount
End Function
Thanks