+ Reply to Thread
Results 1 to 10 of 10

Need help writing a macro for work that can loop through reference numbers

  1. #1
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Need help writing a macro for work that can loop through reference numbers

    I have attached a screencap of an example source table that I am trying to write a macro to manipulate each day. Starting conditions are that I have data in column A and B. Column A would be reference numbers that may be on one line, or more likely, on multiple lines repeating with varying counts. Column B is the weight associated with each line. I would need a macro that could loop through column A, determine if the ref number has changed, and then calculate/populate column C. Column C is the % of the total weight for the unique reference number. I have illustrated this in the table using column D. This is taking me incredible manual effort to complete right now and I do know VBA, I just don't know how to loop a variable range in this case and I'm sure there is someone on this forum that could write a smooth function in their sleep. Help or advice on where to start is greatly appreciated.

    Thanks, Tom

    Capture.JPG
    Last edited by Easy88; 05-14-2014 at 12:05 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Need help writing a macro for work that can loop through reference numbers

    Please don't illustrate it in a picture of a workbook, illustrate it in sample workbook ... the one you made a picture of.

    There's nothing that can be done with a picture of a workbook, other than recreate it, and I have no plans to do that.

    You don't really need a macro, more likely a simple formula copied down ... so a macro could just drop in the simple formula.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Need help writing a macro for work that can loop through reference numbers

    TMS-

    Thanks for the response, I have attached the workbook example as requested. If you can show me how to do this in a formula, I would absolutely be learning something valuable. I thought the issue would be
    solved via macro as it appeared that looping would be involved, but if you can solve via formula that would be preferable of course. Thanks for the response.

    Tom (Easy88)
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Need help writing a macro for work that can loop through reference numbers

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


    The code:

    Please Login or Register  to view this content.

    And see the updated example.

    Regards, TMS
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Need help writing a macro for work that can loop through reference numbers

    TMS-

    Excellent. I'll give it a shot and reply back. Thank you so much for the quick help.

    Tom

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Need help writing a macro for work that can loop through reference numbers

    You're welcome.



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


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    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


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Need help writing a macro for work that can loop through reference numbers

    TMS-

    I took a look at your code and example and it will not work for my needs. To be more specific, my starting conditions are that columns A and B only exist, ... I need to calculate column C. Your code references column C but I have manually added these formulas to help show what I am trying to do. I need something that can calculate column C's values for me only give column A and B. This is the core issue I am having as the calculation range changes depending on how many repeats there are in column A. I appreciate the effort thus far sincerely.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Need help writing a macro for work that can loop through reference numbers

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



    The code:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-13-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Need help writing a macro for work that can loop through reference numbers

    Perfect, exactly what I needed and I learned something in the process. THANK YOU.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Need help writing a macro for work that can loop through reference numbers

    Good. Please mark the thread solved as described in post #6.

    Regards, TMS

+ 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. Novice with VBA and macro writing needing help to loop a macro unti no data
    By jrongone in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-25-2013, 12:19 PM
  2. [SOLVED] Trouble with macro - Loop through all work sheets
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-06-2013, 05:23 AM
  3. My loop macro doesnt work
    By matdog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2010, 02:32 AM
  4. Writing numbers using Macro
    By d_s in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2009, 07:01 AM
  5. Macro Writing Reference?
    By burnsbyrne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2005, 09:31 AM

Tags for this Thread

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