+ Reply to Thread
Results 1 to 12 of 12

Macro that counts weeks from start date to end date

  1. #1
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Macro that counts weeks from start date to end date

    I'd appreciate your help.

    I have macro that counts weeks in between two dates, as seen in file after pressing the button.

    Please Login or Register  to view this content.
    I have problem if 'end date' is in next year, therefore I would need a code that would recognize 'next year'.
    Current year weeks are as from column BO to DN and next year should start with week 1 as from column DO.

    Any suggestions?
    Many thanks!
    Attached Files Attached Files
    Last edited by Tona; 04-15-2016 at 05:57 AM.

  2. #2
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Macro that counts weeks from start date to end date

    Tried following that, but couldn't. Never mind, why not just use the DATADIFF funtion to get the whole number of weeks between 2 dates?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro that counts weeks from start date to end date

    Please see attached file, might help your understanding.
    Thanks!

  4. #4
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Macro that counts weeks from start date to end date

    It seems you want to simply add week numbers. As a start, perhaps
    Please Login or Register  to view this content.
    As there's no headings for the columns, it's difficult to know where the initial value should be placed. It may need adjusting,

  5. #5
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro that counts weeks from start date to end date

    Thank you for effort.

    As you can see in attached file the formula works perfect if my start date and end date are both in 2016. Column BO is week1, BP week2, BR week3, etc. Meaning if start date is 13.1.2016 (week2) and end date is 27.1.2016 (week4) it will start by imputing weeks as from column BP and placing into cell BP3 number 2, then number 3 into BQ3 and number 4 into BR3.

    The last week of the present year is week 52 presented in column DN. Now if end date is in 2017 (meaning that counting exceeds 52) instead of starting it again with week1 in column BO, I'd like it to continue placing week1 (1) into column DO and continue. So basically I'll have weeks for two years in the same row.

    Hope it's clearer.

    I appreciate help.
    Last edited by Tona; 04-15-2016 at 04:02 AM.

  6. #6
    Forum Contributor
    Join Date
    09-03-2015
    Location
    IE
    MS-Off Ver
    2003 - 2016
    Posts
    258

    Re: Macro that counts weeks from start date to end date

    Silly day - I can't understand what you mean. I should leave this for someone else. Sorry.

  7. #7
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Macro that counts weeks from start date to end date

    Try this amendment to your code:

    Please Login or Register  to view this content.
    It looks at the date columns instead of the weeks columns.
    多么想要告诉你 我好喜欢你

  8. #8
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro that counts weeks from start date to end date

    Yes sir!

    But I would need small amendment: instead of week 53 I would need max 52 weeks, and when eg. start week is week2 I need it to fill week2 aswell, not starting with week3.

    I appreciate it!

  9. #9
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Macro that counts weeks from start date to end date

    Hi, the week is controlled by the Format function.

    Below is the code you can tweak to your needs. Maybe you can try using type 3.
    Please Login or Register  to view this content.
    Constant Value Description
    vbUseSystem 0 Use NLS API setting.
    vbFirstJan1 1 Start with week in which January 1 occurs (default).
    vbFirstFourDays 2 Start with the first week that has at least four days in the year.
    vbFirstFullWeek 3 Start with the first full week of the year.

  10. #10
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro that counts weeks from start date to end date

    Thank you for suggestions.

    EU calendar stops at week 52. Not sure how to tackle the problem. And how to start the count with the start week instead of +1.

  11. #11
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Macro that counts weeks from start date to end date

    When do you start counting the week number?
    1st Jan? Use type 1
    First week that has at least 4 days in the year? Use type 2
    First full week in the year? Use type 3

    Normally, counting from 1st Jan usually gives a week 53. What would you do if you want only up to week 52?

  12. #12
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro that counts weeks from start date to end date

    Solved.

    Many thanks!

+ 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. Macro: check today date with start date and open a file in stored location
    By Topa2 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-10-2016, 11:39 AM
  2. Counting if data falls on date between Start Date, End Date or Possible End Date
    By JessHasQuestions in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 07-26-2014, 08:01 AM
  3. [SOLVED] Error check for Start date & End date in a macro
    By kmahesh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-27-2014, 05:21 AM
  4. List of Weeks from a start date and an input number
    By SRBetteridge in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-22-2014, 03:39 AM
  5. Replies: 1
    Last Post: 10-02-2012, 02:42 PM
  6. [SOLVED] Calculate date based on number of weeks or months after start date
    By wotsup in forum Excel General
    Replies: 3
    Last Post: 08-17-2012, 06:00 AM
  7. [SOLVED] Weeks Active from Start and Close Date
    By bh2 in forum Excel General
    Replies: 3
    Last Post: 03-27-2012, 05:20 PM

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