+ Reply to Thread
Results 1 to 13 of 13

Macro loop: Copy value down until it meets next number

  1. #1
    Registered User
    Join Date
    05-20-2012
    Location
    Tokyo
    MS-Off Ver
    Excel 2007
    Posts
    10

    Macro loop: Copy value down until it meets next number

    Hi, I am new to this and wonder if you can help.

    I have a text file which is generated from a mainframe computer. I need to sort the data but since there is no identifyer, I need to create a column, copy the name (highlighted in the yellow lines) from the cells that start with 'ACCESSORID = BSaaaa NAME = AAA'. Note that the 'aaaa' are numbers and will be different for each record, and so as 'AAA'.

    The name can be extracted from these lines and be taken from the characters after 'NAME ='

    So hopefully, I can use a macro to create a new column (say A) and copy the cells with names down in the new column (the name will change at every few lines when the record in the adjacent column changes.)

    Thanks very much in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Macro loop: Copy value down until it meets next number

    I am not sure I understood what you were after, but anyway have a look at the file and tell me if that is what your were after.
    Attached Files Attached Files
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    05-20-2012
    Location
    Tokyo
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro loop: Copy value down until it meets next number

    Thanks for your prompt reply. Unfortunately, this is not what I need. I have added a page 'Results' which is what I am after. Thanks.
    Attached Files Attached Files

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Macro loop: Copy value down until it meets next number

    Ok Try This,
    If you want the names in column B let me know?

    Also, will the name always be 3 digits?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-20-2012
    Location
    Tokyo
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro loop: Copy value down until it meets next number

    Thanks so much. This is it. Can you let me know whether this will work if the file has many more records? Thanks.

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Macro loop: Copy value down until it meets next number

    I just have one concern, will the extracted string always be 3 digits? Eg, can it be "AAAA" or "EEEE" both these have 4 digits.

    As long as the data is in Column A, it will work with as many records as you have room for on the sheet in column A.

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro loop: Copy value down until it meets next number

    hi bone123, formula option
    Attached Files Attached Files

  8. #8
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Macro loop: Copy value down until it meets next number

    I updated the code to allow for the possibility of the name having more than 3 digits. Please use this code.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    05-20-2012
    Location
    Tokyo
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro loop: Copy value down until it meets next number

    thanks. you are right, the names will have different number of charcters. actually the name format is xxx,uuu

  10. #10
    Registered User
    Join Date
    05-20-2012
    Location
    Tokyo
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro loop: Copy value down until it meets next number

    Thanks, this is a great and simple solution to my problem. I do not quite understand the formula though. Do you mind telling me what it actually does? Thanks.

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro loop: Copy value down until it meets next number

    the formula does the following:
    1. Looks for "NAME =" string
    2. If it's not found, the formula result equals to the value of one cell above
    3. If it's found, position of the string + 13 (length of "NAME =" + 1 symbol) gives the start position of the string after "NAME =", it will take any length string

  12. #12
    Registered User
    Join Date
    05-20-2012
    Location
    Tokyo
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro loop: Copy value down until it meets next number

    Thanks very much.

  13. #13
    Registered User
    Join Date
    05-20-2012
    Location
    Tokyo
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Macro loop: Copy value down until it meets next number

    Thanks very much for the 2 solutions provided. It is actually only a start. With that, I managed to manually manipulate the data so that I have a column with names and a column with profiles.

    Separately, I have 2 more mapping tables. One is a table of model profiles that tells me which profiles under the model profiles and another table that tells me who should be under which model profiles.

    I spent a few hours to manually check to make sure that people under the respective model profiles have been set up properly. What I did was to pivot the information to have the names in the columns and profiles in the rows. Then I had to manually match out the ones in the model profiles and color code them.

    In the end, I just investgated the items that are not color-coded.

    That sounds complicated. However, my current question is a very simple one. Do you think it is possible to automate the above using Excel or will I have to use Access?

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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