+ Reply to Thread
Results 1 to 9 of 9

Macro Required to added week numbers to columns

  1. #1
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Macro Required to added week numbers to columns

    Hi,

    Every week I get sent a spreadsheet with the hours booked against specific codes, however, each weeks data is in a separate column (from weeks 1-52).

    What I require is a macro that will check the heading title of each weeks data e.g. WK01, WK02 etc, work out what week it is and input the week number in a new column (Week No) corresponding to that weeks data and also total the time for that week and enter in the Total Hours column

    Please see attached a sample spreadsheet for clarity.

    Please also note that I have asked this question before (http://www.excelforum.com/excel-gene...o-columns.html) and DonkeyOte kindly supplied me with the code to work out the week number i.e.

    =IF(COUNT($D2:$BC2),SUBSTITUTE(LOOKUP(9.99999999999999E+307,$D2:$BC2,$D$1:$BC$1),"Hrs WK",""),0)+0

    however, as the weeks progress I have to manually copy the week number down and add the totals up so I believe a macro would be the best option as I am currently repeating the same task every week.

    The macro needs to:-

    (a) work out the week number and enter in ‘Week No’ column
    (b) macro to copy each weeks data into Total Hours column

    I would be most grateful for any assistance in this matter

    Many thanks in advance


    Regards


    Rob

    N.B. Excel version 2003
    Attached Files Attached Files
    Last edited by robertguy; 02-02-2009 at 03:26 PM.
    Rob

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Macro Required to added week numbers to columns

    still dont think you require macro
    in g2
    =MATCH(99^99,I2:BH2) dragged down
    and in h2
    =SUM(I2:BH2)
    dragged down
    Last edited by martindwilson; 02-02-2009 at 11:23 AM.

  3. #3
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Unhappy Re: Macro Required to added week numbers to columns

    Martin

    sorry I can't seem to get =MATCH(99^99,I2:BH2) to work !

    I'm I doing something wrong ?


    Rob

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Macro Required to added week numbers to columns

    what does it say?
    then again if you are using the same one you posted, its coz column G is formatted as text
    it needs to be formated general first
    then write in the formula.

  5. #5
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Unhappy Re: Macro Required to added week numbers to columns

    Martin,

    thanks for getting back to me it is very much appreciated. That said, I reformatted column 'G' and it does now report the last week with data in i.e. I:BH.

    However, what I was after is for the code/macro to look in each column i.e. I:BH to check which columns have data in (>0) and then using the weeks column heading e.g. Week 2 insert the week number in the associated cell in column 'G' (WK No)

    Any assistance would be greatly accepted

    Regards

    Rob

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Macro Required to added week numbers to columns

    well it works on the principle that nothing is entered in in a column until you need to, why put 00.00 in? just leave blank then the match function finds the last column with a number in it(which would = week number) unless someone hasnt hours that week then put in 00.00 for them
    Last edited by martindwilson; 02-02-2009 at 02:39 PM.

  7. #7
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Smile Sorted

    Martin,

    thanks again, based on what you said...I went to Tools, Options and on the View tab unchecked 'Zero Values'....and guess what ???


    It worked a treat !!

    Many many thanks you have saved me hours of boring repetitive copying and pasting over the next coming year.

    If ever your in Cardiff I’ll buy you a pint or six !!


    Best Regards


    Rob
    Last edited by robertguy; 02-02-2009 at 02:59 PM. Reason: to mark resolved

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Macro Required to added week numbers to columns

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Macro Required to added week numbers to columns

    its probbly best if you leave that on as you may want to return the week number of someone doing 0 hours better to high light all cells in range and clear contents to make sure they are all blank.

+ 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