+ Reply to Thread
Results 1 to 8 of 8

Issue with Week# to Date functiion after the new year

  1. #1
    Registered User
    Join Date
    02-11-2016
    Location
    Wisconsin
    MS-Off Ver
    07-360
    Posts
    53

    Issue with Week# to Date functiion after the new year

    I am using the following code to generate the last date of a week based on the week number. Everything has worked well until the new year hit and now the dates are off by a week (week 1 shows a date of 12/31/2016 instead of 1/7/17). This code has worked well in the past (has not had to deal with new year's). Could this be because January 1st was on Sunday? Is there anything I can do to make this function for years to come? I have been trying to get this working for a while and any help would be greatly appreciated.
    Please Login or Register  to view this content.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: Issue with Week# to Date functiion after the new year

    You don't need VBA.
    This would work...

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Writed in VBA it can be:

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Issue with Week# to Date functiion after the new year

    Hi,

    I'd simplify it to

    Please Login or Register  to view this content.
    Or as just a formula in a cell
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Where A1 contains the week number
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: Issue with Week# to Date functiion after the new year

    Yea, I'm missing last part.

  5. #5
    Registered User
    Join Date
    02-11-2016
    Location
    Wisconsin
    MS-Off Ver
    07-360
    Posts
    53

    Re: Issue with Week# to Date functiion after the new year

    Both answers have Jan. 1st as the first day of the week no matter which day it falls on. This means that no matter the year, the end of week 1 always gets reported as 1/7/xxxx I need the week to start on Sunday. I have found that the issue in my original post happens if the first of the year takes place on Sunday - Wednesday and does not happen the rest of the week. I have tried removing vbfirstfourdays from my code and this issue is still occuring. I may just have to do an if statement looking at the value produced by the weekday function.

  6. #6
    Registered User
    Join Date
    02-11-2016
    Location
    Wisconsin
    MS-Off Ver
    07-360
    Posts
    53

    Re: Issue with Week# to Date functiion after the new year

    This seems to have taken care of it. If anyone knows of a more elegant solution (or why it didn't work originally), please let me know as I am still learning. Thanks!
    Please Login or Register  to view this content.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Issue with Week# to Date functiion after the new year

    Quote Originally Posted by mnadamn19 View Post
    Both answers have Jan. 1st as the first day of the week no matter which day it falls on. This means that no matter the year, the end of week 1 always gets reported as 1/7/xxxx I need the week to start on Sunday. I have found that the issue in my original post happens if the first of the year takes place on Sunday - Wednesday and does not happen the rest of the week. I have tried removing vbfirstfourdays from my code and this issue is still occuring. I may just have to do an if statement looking at the value produced by the weekday function.
    That's not correct.
    When the Year is 2017 the formula in #3 returns Saturday 7 January for week1 which is what you want.
    Next year the same formula will return Saturday 6 January 2018. You can easily demonstrate this by temporarily adding +365 to the year part of the formula to force it to be 2018. i.e.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 01-02-2017 at 08:20 PM.

  8. #8
    Registered User
    Join Date
    02-11-2016
    Location
    Wisconsin
    MS-Off Ver
    07-360
    Posts
    53

    Re: Issue with Week# to Date functiion after the new year

    Sorry about that, I see what i did wrong. I only replaced the first year(date) with a year not the second as well. It does work in the formula form but I am getting a type mismatch with the function. As I have figured out how to get my code to work, I am just going to stick with that. Thanks
    Last edited by mnadamn19; 01-02-2017 at 11:09 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Date from Week and Year, Std formatting
    By torers in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-26-2015, 08:36 AM
  2. [SOLVED] Get the date of saturday in a week from a week number / year
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2015, 06:56 PM
  3. Find date from year and week number
    By pnperl in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-17-2014, 04:04 AM
  4. calculating month to date, year to date, week to date
    By labogola in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2014, 05:21 AM
  5. Help with date forecasting and week of the year
    By sandman1145 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-24-2013, 10:52 AM
  6. Replies: 1
    Last Post: 12-15-2011, 05:32 AM
  7. Replies: 1
    Last Post: 08-23-2005, 11:42 AM

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