+ Reply to Thread
Results 1 to 5 of 5

weeknum & VBA

  1. #1
    Registered User
    Join Date
    01-05-2010
    Location
    Lausanne, Switzerland
    MS-Off Ver
    Excel 2003
    Posts
    7

    weeknum & VBA

    Hello hello,

    Freshly registered on this forum, I'm here to find a little support with some of Excel functions I'm still not used too.. I'm very new in VBA so please, accept per advance my excuses if I'm not 100% clear with the terminology..

    Well.. I got a file from my boss that is linked to an online table. This table contains customer contacts infos such as account number, activation date & time, etc, etc.. (1 contact = 1 line)

    Now (for "quick filtering reasons" he said), my boss "needs" to have also in the sheet the week number for every contact we had..(as well as Month & Year)
    and as the list grows up everyday with new entries, I thought I could use VBA..
    so I wrote a little something that uses the date&time column to have the wanted infos added on every line :

    Please Login or Register  to view this content.
    It works fine with the Month & the year, both return the correct value in the right cells.

    But I can't find a way to have it working with the weeknum one.. it returns me a 4 digit value...

    For example, with "23.12.2009 09:07" (cell format = custom dd.mm.yyyy hh:mm), the weeknum returns me the value 5740 (when cell format is general, and "01.07.1905 00:00" when in date format) when it should returns me 52!

    my only explanation is that it calculates the amount of weeks from 01.01.1900 to 23.12.2009 but yeah... it's not exactly what I need..

    Does anyone know how I could solved this issue ? or how I could pass by ?

    Thanks in advance for your answer,
    I hope you'll understand my question, I'm not that used to write "technical" things in english..

    merci merci,
    steve

    Last edited by soakaos; 01-06-2010 at 12:08 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: weeknum & VBA

    Hi Soakaos. Welcome. Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to edit that post above and put code tags around that code you used. (or just remove it...)

    The WEEKNUM() formula needs one more parameter:

    =WEEKNUM(G2,1)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-05-2010
    Location
    Lausanne, Switzerland
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: weeknum & VBA

    hi,

    I've edited my post as recommended, thanks for the info and thanks for your quick answer.

    Unfortunately, it doesn't work better with =WEEKNUM(G2,1) or =WEEKNUM(G2,2).. I'm still getting the same odd result.. but it looks like the correct result appears in the cell for less than a second and gets replaced by the 4 digit value.. there's no other code or formula in the sheet, so I really don't understand what goes wrong..

    and if I write the formula myself directly on the worksheet, it works like it's supposed to..

    but examples are better than words, so I've uploaded a light version of my file.. I hope some of you guys will take this as a challenge !!

    Thanks in advance for your attention & answers,
    steve
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: weeknum & VBA

    Your macro was written is such a way that it was adding formulas all over the place every time you made any sort of change anywhere.

    Better, we'll just watch column F and enter the formulas in I, J, and K on the rows you just changed only. This should keep it fast and accurate, and the odd behavior goes away.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-05-2010 at 01:32 PM.

  5. #5
    Registered User
    Join Date
    01-05-2010
    Location
    Lausanne, Switzerland
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: weeknum & VBA

    hi,

    thx again for your answer JBeaucaire. I've changed my code with yours and it works now effectively a lot better.

    I also had an issue with the fact my company uses ISO week standards.. so I've searched and added this code into a module

    Please Login or Register  to view this content.
    and then changed "=weeknum(RC6)" into "=IsoWeekNumber(RC6)" and now it works perfectly.

    Thanks again for your precious help,
    and have a nice happy new year !!!!!

+ 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