Exclude Public Holidays

Nathan95

New Member
Joined
Mar 1, 2020
Messages
34
Office Version
  1. 2010
Platform
  1. Windows
Hey All I have the bellow code which inputs all the dates within a date range that is provided through a user form which excludes weekends. Was just also looking to exclude any public holidays from a given list in a diffrent sheet called "Settings"

Any help would be appreciated.

Private Sub cbInputleave_Click()
Dim i As Long, k As Long, arr()
Dim FirstDate As Date, LastDate As Date
Dim rBlanks As Range
Dim ssheet As Worksheet
Dim ctl As Control
Dim Index As Long

Set ssheet = ThisWorkbook.Sheets("Mark Leave")
FirstDate = tbstartdate.Value
LastDate = tbenddate.Value

ReDim arr(1 To LastDate - FirstDate + 1, 1 To 1)
For i = FirstDate To LastDate
If Weekday(i, 2) < 6 Then
k = k + 1
arr(k, 1) = i
End If
Next
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this
VBA Code:
If Weekday(i, 2) < 6 And WorksheetFunction.CountIf(Sheets("Settings").Range("A2:A100"), i) = 0 Then
    k = k + 1
    arr(k, 1) = i
End If
 
Upvote 0
Solution
Try this
VBA Code:
If Weekday(i, 2) < 6 And WorksheetFunction.CountIf(Sheets("Settings").Range("A2:A100"), i) = 0 Then
    k = k + 1
    arr(k, 1) = i
End If

Perfect thanks for that!
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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