Consulting

Results 1 to 5 of 5

Thread: exclude holidays when calculating between dates

  1. #1

    exclude holidays when calculating between dates

    Hi Guys!

    I have the below code that is currently excluding weekends in calculated value. However I also want this to exclude holiday days. I have read stuff about networkdays but I can't make any sense of it. Is there anyway I can amend below to exclude UK holiday days?

    PHP Code:
    .Range("I" lCurrentPhaseLine).Value Application.WorksheetFunction.WorkDay(.Range("E" lCurrentPhaseLine).Value, -10

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to set up a list of holidays and include that range as the 3rd parameter to Workday.

    Networkdays calculates the number of days between two dates, if you just want a date forward or back of a given date, you only need Workday.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks for your quick response xld!

    Do you mean create a range in excel? eg create a worksheet within same workbook e.g on sheet2 and create range range A1:A15 where I list all holidays dates. How would I then incorporate this range in below?:
    [VBA].Range("I" & lCurrentPhaseLine).Value = Application.WorksheetFunction.WorkDay(.Range("E" & lCurrentPhaseLine).Value, -10)[/VBA]

    Sorry I'm only a VBA novice

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes in Excel, and as I said, add the range as parameter 3

    [VBA].Range("I" & lCurrentPhaseLine).Value = _
    Application.WorksheetFunction.WorkDay(.Range("E" & lCurrentPhaseLine).Value, -10, Range("A1:A15")) [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Awesome! Thank you very much xld

Posting Permissions

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