+ Reply to Thread
Results 1 to 13 of 13

Merging rows of data and insertin rows conditionally

  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Merging rows of data and insertin rows conditionally

    Hi guys,

    I've given up on this one...it's just too hard. I'm wondering if you can help?

    I have an excel worksheet with over 9000 rows of information (contact details for companies). There are upto 5 columns.

    The current format of the sheet looks like this:
    Column A...............Column B...............Column C...............Column D...............Column E
    Name:.....................Any Company
    Address:.................Unit 123..................Any Road...............Any Town
    City:........................Any City
    Products:
    *Widgets
    *Widget Tops
    Brands:
    *Willy Widget
    *Widget Pops
    *Silly Billy


    What I need to achieve is the following:
    • After every row that contains the entry "Address:", insert a new row with the entry "Address 2:" in Column A.
    • Where there is an entry is column c, append it to the end of the entry in column b with a hyphen seperating the 2 entries (i.e. merge the columns B and C).
    • Where there is an entry is column D or E, merge the 2 together, seperated with a hyphen, and then place this new entry on the next row (Address 2 that we created before) in column B.
    • Finally, I need to be able to select the rows underneath each company that contain the "products" and "brands", merge the rows into one cell and copy them over to column 2.
    (I don't mind having to do the selection of the rows by hand, as some companies have 14 products listed and others have only 3, but I'd like to know the easiest way to merge the cells into one whilst keeping all the data)


    What I need to end up with (Compared to the top example) is this:

    Column A...............Column B...............
    Name:.....................Any Company
    Address:.................Unit 123 - Any Road
    Address 2:.....................Any Town
    City:........................Any City
    Info:........................Products: *Widgets *Widget Tops Brands: *Willy Widget *Widget Pops *Silly Billy


    I need the data formatted this way as it's going to be imported into another program which lists the fields exactly like this.

    Can you think of any ways to do this, or offer any solutions?


  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Merging rows of data and insertin rows conditionally HARD

    Hi

    Formatting is really hard to understand submitted this way. Build and attach an example workbook showing your before and after structures. Much easier to follow.

    rylo

  3. #3
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Merging rows of data and insertin rows conditionally HARD

    Quote Originally Posted by rylo View Post
    Hi

    Formatting is really hard to understand submitted this way. Build and attach an example workbook showing your before and after structures. Much easier to follow.

    rylo
    Sorry Rylo...will do!

  4. #4
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Merging rows of data and insertin rows conditionally HARD

    Quote Originally Posted by rylo View Post
    Hi

    Formatting is really hard to understand submitted this way. Build and attach an example workbook showing your before and after structures. Much easier to follow.

    rylo
    OK Rylo...here we go.

    The first worksheet is how it currently looks (just 2 companies, not all 500), and the second worksheet is exactly how I need it to be.

    Can you or anyone else help? I'd be really greatful! Thanks.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Merging rows of data and insertin rows conditionally

    Hi

    See how this goes.
    Please Login or Register  to view this content.
    rylo

  6. #6
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Merging rows of data and insertin rows conditionally

    Quote Originally Posted by rylo View Post
    Hi

    See how this goes.
    Please Login or Register  to view this content.
    rylo

    AMAZING!!!! I am so relieved!

    It did stop processing them at row number 10948, leaving about 20 companies still left to do, but if that's an Excel problem (maybe it limits the amount or something?) then I'll do those 20 companies by hand! You have saved me days of copy and pasting...thanks so much.

    I do have one other thing (only small compared to what you just did)...each of the company name entries currently ends with a space and a letter. The letter is always either D or M (indicating if they're a Manufacturer or Distributor) (you can see that on the original file I attached for the 2 companies).

    Is there some code that could strip that letter, and insert a new row with the fields "Company Type" in column 1, and either "Manufacturer" or "Distributor" in column 2?

    If there is, it would mean my work is finished for today. I'd appreciate it a lot :whereisthe'beg'smilie:

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Merging rows of data and insertin rows conditionally

    Hi

    OK, try this. I think I've also fixed the missed out rows problem as well.

    Please Login or Register  to view this content.
    rylo

  8. #8
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Merging rows of data and insertin rows conditionally

    Quote Originally Posted by rylo View Post
    Hi

    OK, try this. I think I've also fixed the missed out rows problem as well.

    Please Login or Register  to view this content.
    rylo
    You're almost there!! 99%.
    • Rows 10966 tthru 11702 (the last row) haven't been processed.
    • Any chance the D or M could be stripped from the end of the company name?
    • It inserts the company type brilliantly, but howabout making it insert the words "Distributor" or "Manufacturer" instead of just the letters D or M as it goes?

    I think it's my round at the bar by the way!

  9. #9
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Merging rows of data and insertin rows conditionally

    Hi

    Can you please not quote previous posts in your repy. Just clogs things up.

    Modified for the company name and company types.

    I'm not sure why the extra rows aren't actioning. Can you confirm that there will always be something in column A, that this can be used to determine the last row.

    Please Login or Register  to view this content.
    rylo

  10. #10
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Merging rows of data and insertin rows conditionally

    Hi Rylo,

    Thanks for your help on this.

    I tried the latest code and it does everything correctly, apart from not finishing the list of entries.

    I can confirm that there is always something in Column A so it can be used to determine the last row.

    I got a Runtime error, and when pressing debug; it highlighted this line:

    Please Login or Register  to view this content.
    I have also tried splitting the list (A-M on one sheet and N-Z on the next), but the macro still stops too early on both sheets.

    Would it help you if wrote the word "rylo" in the very last row of column A as the identifier for where the list ends?

    Thanks.

    EDIT TO ADD: I think I have found the problem. Sometimes there are 1 or 2 blank rows between the company name and the Address: field. When this happens, the macro takes the company name and adds it to the previous entries "products" list, hence there is no company or letter "M" or "D" in the next entry, creating the runtime error.

    We might need to add some code at the start to remove any empty rows above the Address: row.
    Last edited by classixuk; 09-28-2010 at 09:58 AM.

  11. #11
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Merging rows of data and insertin rows conditionally

    Hi

    1) can you put up an amended example file that shows how some of the entres would appear with the blank lines. Make sure that you have a mixture of both standard and non standard entries and that they cover all possibilities.

    2) I'm not sure what is happening with it not processing the full range. Can you try to replicate the problem in an example file. Another thing to try. Go to the last cell in column A, then do a ctrl up arrow. Where does this take you? To the last record to be processed? Or are there "entries" all the way down to the last cell so that it isn't really blank?

    rylo

  12. #12
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Merging rows of data and insertin rows conditionally

    Hi Rylo,

    Thanks for the help.

    Attached is the amended example file you asked for showing standard and non standard entries.

    The CTRL and UP took me to the last record to be processed.

    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Merging rows of data and insertin rows conditionally

    Hi

    Added bit to remove the extra rows. Have you managed to build an example file that replicates the problem of not actioning all the items?

    Please Login or Register  to view this content.
    rylo

+ 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