Results 1 to 4 of 4

Thread: Number of week

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Location
    Slovakia
    Posts
    20

    Number of week

    Hello,
    I didn't find any answer of my question. How I can obtain in VBA number of actual week ? I know only function in excel
    Can somebody helps to me ?

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Number of week

    Code:
    format(now,"ww")
    Check t he help files on format function. The above should return a week number.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Location
    Slovakia
    Posts
    20

    Re: Number of week

    Quote Originally Posted by Ecniv
    Code:
    format(now,"ww")
    Check t he help files on format function. The above should return a week number.
    Thank You,
    but there is a small problem.
    If I run this code now answer was 33-rd week, but according calendar is only 32-nd week.

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Number of week

    I think I read a little bit about a starting week date thing in the help file on format.

    from MS Excel help on Format
    Symbol Range
    d 1-30
    dd 1-30
    ww 1-51
    mmm Displays full month names (Hijri month names have no abbreviations).
    y 1-355
    yyyy 100-9666
    Starts its count at 1 so just minus one - should be ok.
    If you are not sure try a couple of tests in the immediates window (ctrl+g)
    Code:
    ?format(cdate("01 jan 2005"),"ww")
    ?format(cdate("01 mar 2005"),"ww")
    ?format(cdate("01 jul 2005"),"ww")
    ?format(cdate("01 oct 2005"),"ww")
    Or put your own dates in and work out which week it should be in.

    also
    from MS Excel help on Format
    Format(expression[, format[, firstdayofweek[, firstweekofyear]]])

    The firstweekofyear argument has these settings:

    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.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width