+ Reply to Thread
Results 1 to 15 of 15

Separate comma-delimited values to rows

  1. #1
    Registered User
    Join Date
    10-21-2009
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Separate comma-delimited values to rows

    I have tried doing this myself, cloning parts and pieces from others, but can not get it to work right.

    I have an excel sheet I create with lots of inventory items distributed amongst several locations. The first column is a location field where several 1-2 digit location codes are seperated by commas. I would love to get the macro to copy each row, once for each location code, onto a new tab as a new longer list. Because the amount of data per row varies, I need the entire row to be copied to the new tab.

    EX:
    GOING FROM THIS...
    LOC ITEM etc...
    1, 2, 5 ITEM1 moredata...
    1, 5, 10 ITEM2 moredata2...

    TO THIS ON NEW TAB...
    LOC ITEM etc...
    1 ITEM1 moredata...
    2 ITEM1 moredata...
    5 ITEM1 moredata...
    1 ITEM2 moredata2...
    5 ITEM2 moredata2...
    10 ITEM2 moredata2...
    Attached Files Attached Files
    Last edited by sporto; 10-23-2009 at 02:00 AM. Reason: Attach sample file

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Seperate comma-delimited values in cell to new rows on seperate tab

    Hi Sporto
    Try the attached and see if it does what you want. Let me know if you have issues.
    Hope this helps.
    John

    PS: I re-read your post and see you want this copied to a new tab. I'll modify the procedure to do that but check the attached book and see if it does what you want.
    Attached Files Attached Files
    Last edited by jaslake; 10-22-2009 at 08:01 PM. Reason: Add'l Info
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Separate comma-delimited values to rows

    Hi Sporto
    The procedure in this book will add a new sheet as you requested. Let me know of any issues.
    John
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    10-21-2009
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Separate comma-delimited values to rows

    When I loaded the first file with lots of data, something wierd happens to the data past column D. It might be because there is data that will span dozens of columns, not just 4-5. If it copies the entire row width of data to a new tab, then that would be excellent. (PS - Thank you very much for helping me with this problem.)
    Last edited by sporto; 10-22-2009 at 09:22 PM. Reason: Missed a post...

  5. #5
    Registered User
    Join Date
    10-21-2009
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Separate comma-delimited values to rows

    Tried the second file... Everything splits up good and copies to new tab except Column "E" is empty from top to bottom... Odd. I dont know if there is a way to copy a solid row no matter how many columns it spans, or if it needs to detect how wide the row's worth of data goes. Worse case, maybe something that allows to say what last row is if it cannot detect it itself. (PS - Thanks as always for working on this. )

    Attached second file (Rev 1) with sample of possible real data. When run, column "E" data disappears on newly created Tab.
    Attached Files Attached Files
    Last edited by sporto; 10-22-2009 at 09:48 PM. Reason: Attaching last file with real data example in it that fails.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Separate comma-delimited values to rows

    Hey Sporto
    The procedures are built on your sample file. Column E was empty in your sample so i used it for other "stuff" and then I cleared my other "stuff" here
    Please Login or Register  to view this content.
    and here
    Please Login or Register  to view this content.
    So, to make the procedure work, I'll probably need a version of your "real" data (proprietary info removed) so I can accommodate the procedure to your "real" data. Can you provide this?
    John

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Separate comma-delimited values to rows

    Hi Sean
    Take a look at this and see if it works. As always, let me know of issues.
    John
    Attached Files Attached Files

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Separate comma-delimited values to rows

    This routine worked for me.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  9. #9
    Registered User
    Join Date
    10-21-2009
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Thumbs up Re: Separate comma-delimited values to rows

    John, you're the man. Works perfectly no matter how much data I put into the page. Thanks for the last-minute entry there Mike. That file did not clone all data properly if there are more columns though.

    Love this site and all the people here. Thanks again.

    ~Sean Ohlrich

  10. #10
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Separate comma-delimited values to rows

    To handle a varying number of columns (if the max number of columns is in the top row) change this first section
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-21-2009
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Talking Re: Separate comma-delimited values to rows

    Wonderful work. Thanks again for the update on the file!

  12. #12
    Registered User
    Join Date
    09-09-2010
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Separate comma-delimited values to rows

    hi john and hello every one . after one whole day googling i found this website, register and download the rev1.1 file , everything is ok except getting error on below yellow line :

    Sub SplitCells()
    Dim i As Long
    With Application
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    Sheets("DATA1").Range("B" & Col).Select
    For i = 1 To Selection.Rows.Count
    Dim splitValues As Variant
    splitValues = Split(Selection.Rows(i).Value, ",")
    Selection.Rows(i).Resize(UBound(splitValues) - LBound(splitValues) + 1).Value = Application.Transpose(splitValues)
    Next i
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
    End With
    End Sub

    can you help me with this ?
    thanks

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Separate comma-delimited values to rows

    Welcome to the forum,

    Please read ALL the forum rules before posting... you have already broken 2 of those rules.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  14. #14
    Registered User
    Join Date
    02-22-2013
    Location
    Spain
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Separate comma-delimited values to rows

    Hi Everyone, it's my first time on the forum, hope i don't break any rules!
    I need exactly what the sporto rev1.xlsm files does but when i run it on my data which has (1807 rows originally) i get error Run-time error "13" Type mismatch but only after it has already successfully processed about 150 rows. I am using excel 2010.

    Any help would be much appreciated.

    Thanks!
    Ranpal

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Separate comma-delimited values to rows

    Ranpal,

    hope i don't break any rules.

    You have.
    You can not post on someone's thread. You need to start your own thread.

+ 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