+ Reply to Thread
Results 1 to 13 of 13

Separator to row

  1. #1
    Registered User
    Join Date
    02-08-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    6

    Separator to row

    Hello,

    I have an excel file that has in a certain column, different values separated by the pipe character ("|"). I want to create a new row, for each of these values. To be more accurate, I'll give you an example:

    Excel file:

    Id Name Products
    1 John product1|product2|product3
    2 Maria product5|product6|product7


    And I want it to be:

    Id Name Products
    1 John product1
    1 John product2
    1 John product3
    2 Maria product5
    2 Maria product6
    2 Maria product7

    I hope this example was more explanatory.

    Thank you for your help!
    M.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Separator to row

    I suggest you post a small sample workbook.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Separator to row

    Please Login or Register  to view this content.



  4. #4
    Registered User
    Join Date
    02-08-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Separator to row

    Here you go.


    LE:
    @snb, your code gives me a type mismatch, error 13.
    Attached Files Attached Files
    Last edited by mannerheim; 02-08-2011 at 01:41 PM.

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Separator to row

    Try this:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Separator to row

    I forgot to give you permission tot adapt the code..

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by snb; 02-08-2011 at 02:41 PM.

  7. #7
    Registered User
    Join Date
    02-08-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Separator to row

    @StephenR, your solution seems to work
    Just one last question, since I am new to VBA:
    What piece of code sets the column that contains the pipe separator?
    I'm asking this question because some of these files have 3-4 or even 5 extra columns.

    Thanks!
    Last edited by mannerheim; 02-09-2011 at 05:38 AM.

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Separator to row

    This line sets it at two columns to the right of A which is the first column of data, so you could just change the offset:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-08-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Separator to row

    So, if I have to copy more than those three columns of data, I have to change the offset?
    I mean, if I have more than three columns in my excel file, say ten of fifteen and I have to copy all that data, I have to change this as well:

    Please Login or Register  to view this content.
    ?

  10. #10
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Separator to row

    The offset used is the difference between the first column of data and the column with the separated data. Is the separated data always the last column? You'll also have to change the resize but hard to be precise as can only go on the sample you provided.

  11. #11
    Registered User
    Join Date
    02-08-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Separator to row

    I've attached another sample file, to better understand what I am talking about.

    Thanks!
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Separator to row

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-08-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Separator to row

    Thanks, this is perfect!

+ 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