+ Reply to Thread
Results 1 to 8 of 8

How to calculate date of the next DayOfWeek after given date?

  1. #1
    Registered User
    Join Date
    11-01-2011
    Location
    Czech republic
    MS-Off Ver
    Excel 2010
    Posts
    4

    Cool How to calculate date of the next DayOfWeek after given date?

    Hello guys,

    I got to a very challenging Excel problem. I would like to get the list of all [GivenDayOfWeek1] and [GivenDayOfWeek2] in the given month.

    Month is set by a date in A1. [GivenDayOfWeek1] and [GivenDayOfWeek2] can be any day of week from Monday to Sunday and it's set in Cells B1 and C1.

    For example I would like to get all Thursdays and Saturdays from November 2011.

    The result would be (in column A starting at A2):
    Thursday 3. 11. 2011
    Saturday 5. 11. 2011
    Thursday 10. 11. 2011
    Saturday 12. 11. 2011
    Thursday 17. 11. 2011
    Saturday 19. 11. 2011
    Thursday 24. 11. 2011
    Saturday 26. 11. 2011
    Is that even possible? I was able to get the list of all [GivenDayOfWeek1] (let's say Thursdays at cell B1), but I can't add the other day to the formula to be able to fill the rows with that.


    Please Login or Register  to view this content.

    Thank you very much for any help you can provide.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: How to calculate date of the next DayOfWeek after given date?

    Does the attached help ?

    It is based on the WEEKDAY function using 2 as argument ( Monday is 1, Tue, 2, etc..)
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-01-2011
    Location
    Czech republic
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to calculate date of the next DayOfWeek after given date?

    arthurbr thanks for the file. I need to have all the dates in one column, are you able to combine those two formulas together?

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How to calculate date of the next DayOfWeek after given date?

    try this you could hide b1/c1 by putting and on another sheet
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

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

    Re: How to calculate date of the next DayOfWeek after given date?

    With A1 1st of any month, B1 any day as text and C1 any day as text try this "array formula" in A2 confirmed with CTRL+SHIFT+ENTER and copied down as far as needed and further

    =IFERROR(SMALL(IF(COUNTIF(B$1:C$1,TEXT(ROW(INDIRECT(A$1&":"&EOMONTH(A$1,0))),"dddd")), ROW(INDIRECT(A$1&":"&EOMONTH(A$1,0)))),ROWS(A$2:A2)),"")

    ...and if you want 3 or 4 days included you can just add those in D1 and E1 etc. and change the range in the formula......
    Attached Files Attached Files
    Last edited by daddylonglegs; 11-01-2011 at 07:49 PM.
    Audere est facere

  6. #6
    Registered User
    Join Date
    11-01-2011
    Location
    Czech republic
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to calculate date of the next DayOfWeek after given date?

    daddylonglegs thank you for the solution! It looks like it works!

    The only problem is, that I work with MS Excel 2010 without SP1 in Czech version. When I open the file from yours and I confirm the security warning (it would be "Allow editing" in English i guess), I need to manually change the name of the English dates to it's Czech equivalent. Then the function starts working. But when I try to modify the function to my own needs (B1 -> D5 ; C1 -> D6 ; A1 -> B11 ; A2 -> B12) it does't work. At first I thought that I made a typo, but when I tried to change it back to the exactly same state as you send it, it didn't work either. I triple-checked it for typos and nothing was there. The only solution was to re-download your file again. Even if I add a space at the end of your formula
    (the re-downloaded one) and then I delete it, it doesn't work afterwards.

    I also tried to rewrite yours formula (with the same Cells) into the Czech form manually, using http://wwwhome.cs.utwente.nl/~trieschn/excel/excel.html , but it didn't work either.

    Target users will have mostly Czech versions of MS Office ranging from 2003 to 2010, do you know how to edit the function to work at all MS Office product versions?

    Do you know how to solve

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

    Re: How to calculate date of the next DayOfWeek after given date?

    The formula is an "array formula" that needs to be confirmed with CTRL+SHIFT+ENTER, if you modify it that needs to be done again.

    Do that like this

    Select cell with formula, press F2 key to select formula, then hold down CTRLa and SHIFT keys and press ENTER. If doene correctly then curly braces like { and } will appear around the formula in the formula bar

  8. #8
    Registered User
    Join Date
    11-01-2011
    Location
    Czech republic
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: How to calculate date of the next DayOfWeek after given date?

    It worked! Once again thank you for the help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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