Results 1 to 4 of 4

VBA - List Dates excluding Weekends and Holidays

Threaded View

  1. #1
    Registered User
    Join Date
    09-09-2012
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    3

    VBA - List Dates excluding Weekends and Holidays

    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
    Last edited by jeffreybrown; 11-01-2012 at 11:14 PM. Reason: Forum Rule #3. Please use code tags…Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1