Really appreciate if someone could help. This may be a little long. I apologize.
I currently have a function in which when I enter a date that is not a trading day it returns an error.
The Code is:
Private Function ExDates(ExcelDate As Date) As String
' The function determines if a particular date is a trading day
If Year(ExcelDate) <> 2011 Then
ExDates = "CVErr(xlErrValue)"
ElseIf Weekday(ExcelDate, vbMonday) = 6 Then
ExDates = "This date is not a trading day"
ElseIf Weekday(ExcelDate, vbMonday) = 7 Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Jan 3, 2011") Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Jan 26, 2011") Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Apr 22, 2011") Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Apr 25, 2011") Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Apr 26, 2011") Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Jun 13, 2011") Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Dec 26, 2011") Then
ExDates = "This date is not a trading day"
ElseIf ExcelDate = DateValue("Dec 27, 2011") Then
ExDates = "This date is not a trading day"
Else
ExDates = "This date is a trading day"
End If
End Function
Now I have to be able to create a list of dates using vba excluding weekends and the holidays above. What I have now is:
Sub RunExDates()
With Range("A1")
.Value = #1/1/2011#
.AutoFill Destination:=Range("A1:A261"), Type:=xlFillWeekdays
.Application.Run "ExDates"
End With
This actually returns a list of dates excluding the weekends for the year 2011, but is very limited and doesn't exclude the holidays I mentioned.
Could someone help me modify mine or if there's a better solution would be greatly appreciated. Thank You
Bookmarks