+ Reply to Thread
Results 1 to 11 of 11

Add Days, if weekend, subtract 1 or 2 days

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Add Days, if weekend, subtract 1 or 2 days

    Hi,
    S1 = 10/7/2010
    I want T1 to be S1 +45 but to subtract 1 or 2 days if the result ends on a weekend

    I've got it spread out into 4 cells, but would like to combine into one if that is possible or find a better way (the final result to below should be 11/19/10).
    Then there is the question of how to take out holidays in the same way, always going to the working day before.

    S1
    10/7/10

    T1
    Please Login or Register  to view this content.
    U1
    Please Login or Register  to view this content.
    (result is 1)

    V1
    Please Login or Register  to view this content.
    Thank you.
    Last edited by ker9; 10-14-2010 at 12:37 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Add Days, if weekend, subtract 1 or 2 days

    If you're using XL2007 a simple alternative:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Add Days, if weekend, subtract 1 or 2 days

    Thank you - but that won't work if the start date were 10/8 - the start date will vary but will always be a weekday. I am in 2007 but need formulas to work with 2003.

    I've got it to down to one cell for the date and then a 2nd cell for the holidays (Holidays is a range)


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by ker9; 10-14-2010 at 10:31 AM.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Add Days, if weekend, subtract 1 or 2 days

    edit: below posted prior to OP revising above post and introducing holidays component

    Quote Originally Posted by ker9
    Thank you - but that won't work if the start date were 10/8
    For 8th Oct the earlier suggestion would return 22-Nov ... which I believe to be the correct value, if not please outline why.

    edit: regards your holidays requirement - this can be added to WORKDAY
    (which can be used in earlier versions but necessitates ATP be activated)

    If you need a non-ATP dependent version one approach would be:

    Please Login or Register  to view this content.
    there are others

    edit: above not accounting for holidays as was not originally stipulated
    Last edited by DonkeyOte; 10-14-2010 at 10:58 AM.

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Add Days, if weekend, subtract 1 or 2 days

    I like the WORKDAY option that DonkeyOte suggested, you can add in the holiday range, i.e.

    =WORKDAY(S11+45+1,-1,holidays)

    I believe that will work as required whatever the start date

    In Excel 2003 you can add in Analysis ToolPak by using

    Tools > add-ins > tick "Analysis ToolPak". All users would need the add-in enabled.

    Your 2 cell approach won't work if you might have successive holiday dates. This version will take account of holidays without using WORKDAY

    =S11+45-SMALL(IF(WEEKDAY(S11+45-{0,1,2,3,4,5},2)<6,IF(COUNTIF(holidays,S11+45-{0,1,2,3,4,5})=0,{0,1,2,3,4,5})),1)

    That will cope with a maximum of 5 successive non working days.....
    Audere est facere

  6. #6
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Add Days, if weekend, subtract 1 or 2 days

    DonkeyOte:
    My bad - I looked at the calendar wrong and thought 11/22 was a Sunday - sorry!
    Your code works - thank you!

  7. #7
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Add Days, if weekend, subtract 1 or 2 days

    daddylonglegs

    Thank you! Both code options work wonderfully. I'm am going to try using the second option because there are successive holidays coming up in November.

    You are all so very clever and I appreciate your help very very much!!

  8. #8
    Registered User
    Join Date
    08-06-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Add Days, if weekend, subtract 1 or 2 days

    Is there anyway to make this work backwards? In other words, instead of adding to the date, subtracting from a particular date but still accounting for holidays and weekends. I tried changing the 3 plus signs to minus signs, but it didn't work properly.

    S11+45-SMALL(IF(WEEKDAY(S11+45-{0,1,2,3,4,5},2)<6,IF(COUNTIF(holidays,S11+45-{0,1,2,3,4,5})=0,{0,1,2,3,4,5})),1)

    Say S11 was March 1 and I wanted to go back 5 days, skipping weekends; the date returned should be Feb. 23. And if (for some strange reason) Feb 23 was a holiday, then I would like it to return the date of Feb 22.

  9. #9
    Registered User
    Join Date
    08-06-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Add Days, if weekend, subtract 1 or 2 days

    Formula is no longer calculating correctly. =S11+45-SMALL(IF(WEEKDAY(S11+45-{0,1,2,3,4,5},2)<6,IF(COUNTIF(holidays,S11+45-{0,1,2,3,4,5})=0,{0,1,2,3,4,5})),1)


    I hadn't used the worksheet (where this formula resided) for several years. When I put it back into use, I noticed that this formula is no longer working correctly. For example, if S11 = 12 June 2015 and I want to add 15 days (this number is coming from a reference cell), Excel is returning 26 June, not 6 July, which is correct (ignoring weekends and July 3rd as a lieu holiday for July 4).

    Any idea what's going on?

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Add Days, if weekend, subtract 1 or 2 days

    It seems like over the years you've forgotten what the intended purpose of the formula is.

    It adds the #of days FIRST (regardless if they are weekend or holiday).
    THEN tests if that resulting date is a weekend or holiday.
    And if it is, then it falls back to the previous workday.

    So June 26th IS the correct answer for that formula if S11 is June 12 2015.

  11. #11
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Add Days, if weekend, subtract 1 or 2 days

    Actually, the formula seems to add 45 days, not 15

    Quote Originally Posted by ChrisCione2020 View Post
    =S11+45-SMALL(IF(WEEKDAY(S11+45-{0,1,2,3,4,5},2)<6,IF(COUNTIF(holidays,S11+45-{0,1,2,3,4,5})=0,{0,1,2,3,4,5})),1)
    So the correct answer would actually be July 27th.

+ Reply to Thread

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