+ Reply to Thread
Results 1 to 9 of 9

Display Week Number based on special requirements

  1. #1
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Angry Display Week Number based on special requirements

    All,

    I am having the hardest time wrapping my head around this so i have come here for help. I am basically wanting to input any given date and a cell, and have the cell next to it display the week number within the month that date falls on. But there is a catch to it; the week numbers spread across two months depending on the given date.

    Basic Rules:
    1. Dates that fall at the beginning of the month that are on a Sunday, Monday, Tuesday, or Wednesday are considered a part of the first week of the date's current month.
    2. Dates that fall at the beginning of the month that are on a Thursday, Friday, or Saturday, are considered a part of the last week of the previous month.

    3. Dates that fall at the end of the month that are on a Sunday, Monday, or Tuesday are considered a part of the first week of the next month.
    4. Dates that fall at the end of the month that are on a Wednesday, Thursday, Friday, or Saturday, are considered a part of the last week of the date's current month.

    5. Dates that fall in the middle of the month are counted based on rules 1 and 2.

    6. Dates that fall in the middle of the month, the next week begins on Mondays. For example: Jan 6 is still in week 1, Jan 7 starts week 2.

    I have no idea how to come up with a formula for this or if it can even be done.

    In my samples below, i am using the 2013 calendar year.
    Dates at the beginning of the month examples:
    Jan-1 = Week1 of January
    Feb-1 = Week5 of January
    May-1 = Week1 of May
    Aug-1 = Week 5 of July

    Dates at the end of the month examples:
    Jan-31 = Week5 of January
    April-30 = Week1 of May
    July-31 = Week5 of July
    Last edited by PY_; 02-26-2013 at 05:14 PM.

  2. #2
    Valued Forum Contributor Melvinrobb's Avatar
    Join Date
    06-19-2012
    Location
    Manitoba, Canada
    MS-Off Ver
    Excel 2013
    Posts
    1,128

    Re: Display Week Number based on special requirements

    I had a pretty difficult time with this, but here is my solution. I used a helper cell to calculate this, because it will keep your formula a lot cleaner.
    Put your Date in cell B2.
    You can determine the Wednesday of the current week with the following formula in D2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Using this Wednesday date, you can calculate the weeknumber of the current month with the following formula in F2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Please click the * icon below if I have helped.

  3. #3
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: Display Week Number based on special requirements

    That is much closer than what i came up with!

    But try 4/30 in your formula, it shows it as week5 of april but looking at the rules (#3), it should be week1 of may.

    One more rule i forgot to add here ( i am editing my main post to update the rules). The next week begins on Mondays for dates that fall in the middle of the month. For example: Jan 6 is still in week 1, Jan 7 starts week 2.
    Last edited by PY_; 02-26-2013 at 03:34 PM.

  4. #4
    Valued Forum Contributor Melvinrobb's Avatar
    Join Date
    06-19-2012
    Location
    Manitoba, Canada
    MS-Off Ver
    Excel 2013
    Posts
    1,128

    Re: Display Week Number based on special requirements

    It appears as week #1 for me.
    I changed the formula to account for weeks beginning on Monday.
    Let me know if what is in the attached file is correct.
    Attached Files Attached Files

  5. #5
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: Display Week Number based on special requirements

    I must have been an error on my part because i am seeing #1 as well.

    After looking at it, I believe you have done it! Thank you so much Melvinrobb!

  6. #6
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: Display Week Number based on special requirements

    I tried to back date my spreadsheet but it fails in 2012. Should it work the same way every year?

    Example:
    2-Jan-12 through 8-Jan-12 all equal Week 2 but they should actually be Week 1

  7. #7
    Valued Forum Contributor Melvinrobb's Avatar
    Join Date
    06-19-2012
    Location
    Manitoba, Canada
    MS-Off Ver
    Excel 2013
    Posts
    1,128

    Re: Display Week Number based on special requirements

    That is because the 1st is on a sunday, and is obviously week #1, but on Monday a new week starts, in this case week #2.
    How do you fix that? I am not sure.

    I believe this only happens if the year starts on a sunday. Assuming that, this formula seems to work:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The additional formula simply subtracts 1 from the week # IF:
    1. the week month is January
    2. The first day of the year starts on a Sunday

  8. #8
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: Display Week Number based on special requirements

    Well i put a band-aid on it that seems to work for what i tested. Using your original code, i checked to see if the first day of the year falls on a Monday. If it does, subtract 9 vs 2.

    Original
    Please Login or Register  to view this content.
    Modified
    Please Login or Register  to view this content.

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

    Re: Display Week Number based on special requirements

    You should be able to simplify this somewhat. If you have a date in B2 get the week number with this formula

    =INT((6+DAY(B2+3-WEEKDAY(B2-1)))/7)

    using that formula week 1 always starts with the Monday that falls somewhere in the 7 days which includes the last 2 days of the month and the first 5 of the next - that seems to match your requirements although I think your initial description is a bit confusing.....
    Audere est facere

+ 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