VBA UDF to count # of weekend days and holidays between 2 dates

Teeks2k

New Member
Joined
Aug 1, 2017
Messages
20
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.

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
Need some suggestions to help me get this to work.
Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
So this function only half works, it will count the weekends but will totally ignore the second part of the function to look for holidays in the list.
 
Upvote 0

Forum statistics

Threads
1,215,914
Messages
6,127,690
Members
449,398
Latest member
m_a_advisoryforall

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top