VBA to determine next working date excluding holiday List and WeekEnds

mchilapur

Board Regular
Joined
Apr 14, 2014
Messages
126
Hello Experts,
I have a requirement where i need to update a column in excel with dates thats equal to todays Date + 2 days ahead (Ex: 4-Aug + 2 Days ahead).
But the date must not be a weekend (Saturday and Sunday) and also none among the below shown holiday list.
Suppose i am running this Macro Today (4th-August), how can determine next working as 10-Aug based on below holiday list + Weekends.?

I can determine weekends using below code but i need check for holiday list too to determine for how many days i need to count ahead.
Code:
Weekday(MyDate, vbMonday) > 5


Can anyone please help with the VBA code to find this..?


Holiday list
7-Aug-17
8-Aug-17
9-Aug-17
24-Nov-17
25-Dec-17
26-Dec-17
27-Dec-17
28-Dec-17
29-Dec-17

<tbody>
</tbody>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
If your holiday dates are A1:A15 try
=WORKDAY(TODAY(),2,A1:A15)
 
Upvote 0
Hello Fluff,
Thanks for your response. That works great, but I need VBA to determine this.
I need to run this Code on huge data which already has enough formulas in it coz of which it responds bet slowly.

Kindly provide me the script for this.
 
Upvote 0
fluff, can you please provide the script..? Sorry but, are you working on this.. Dont mistake me..
 
Upvote 0
If you want the full code rather than just the method, I will need to know
Sheets names
Data ranges
Holiday ranges
where the formula goes
 
Upvote 0
Hello fluff, i agree and below is the details
I have 2 sheets, 1) Data. 2) Holidays
Data sheet had 13000 plus of rows with A:H column. Column A had the dates on which i pull this report (Todays date).Under column H i need to generate the dates for each entry with criteria as stated in this post.

Holiday sheet has holiday from Range A2:A10.

Hope this helps.
 
Upvote 0
Presuming the dates are actual dates and not strings, and look like:
Holiday
A
1HOLIDAYS
27-Aug-17
38-Aug-17
49-Aug-17
524-Nov-17
625-Dec-17
726-Dec-17
827-Dec-17
928-Dec-17
1029-Dec-17

<thead>
</thead><tbody>
</tbody>
Excel 2010

In a Standard Module:

Rich (BB code):
Option Explicit
  
Public Function Add2DaysAndSkipHolidayList(ByVal dateInputOutput As Date) As Date
Dim Index As Long
  
  dateInputOutput = dateInputOutput + 2
  If Weekday(dateInputOutput, vbMonday) = 7 Then
    dateInputOutput = dateInputOutput + 1
  ElseIf Weekday(dateInputOutput, vbMonday) = 6 Then
    dateInputOutput = dateInputOutput + 2
  End If
  
  On Error Resume Next
  Do
    Index = 0
    Index = Application.Match(dateInputOutput, ThisWorkbook.Worksheets("Holiday").Range("A2:A10").Value, 0)
    dateInputOutput = dateInputOutput + 1
  Loop While Not Index = 0
  On Error GoTo 0
  
  dateInputOutput = dateInputOutput - 1
  
  
  If Weekday(dateInputOutput, vbMonday) = 7 Then
    dateInputOutput = dateInputOutput + 1
  ElseIf Weekday(dateInputOutput, vbMonday) = 6 Then
    dateInputOutput = dateInputOutput + 2
  End If
  
  Add2DaysAndSkipHolidayList = dateInputOutput
  
End Function
  
Sub example()
  MsgBox Add2DaysAndSkipHolidayList(#8/4/2017#)
  MsgBox Add2DaysAndSkipHolidayList(#12/21/2017#)
End Sub

Does that help?

Mark
 
Upvote 0
Cheers for stepping in here Mark, I must have lost this thread somehow.
 
Upvote 0
Works like charm.. Many thanks..
Just curious, what is below code for..?

Code:
[COLOR=#333333]MsgBox Add2DaysAndSkipHolidayList(#12/21/2017#)[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

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