+ Reply to Thread
Results 1 to 15 of 15

Separate comma-delimited values to rows

Hybrid View

  1. #1
    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.

  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: 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
    Cells(Z, 5) = daAnsw
    and here
    Columns(5).ClearContents
    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
    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 Sean
    Take a look at this and see if it works. As always, let me know of issues.
    John
    Attached Files Attached Files

  4. #4
    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.

    Sub CommaDelimitedToRows()
        Const Delimiter As String = ","
        Dim dataRange As Range
        Dim numberArray As Variant, numberRange As Range
        Dim oneCell As Range
        Dim rowNum As Long
        
        With ThisWorkbook.Sheets("DATA").Range("A:C")
            Set dataRange = Range(.Cells(2, .Columns.Count), .Cells(.Rows.Count, 1).End(xlUp))
        End With
        
        With dataRange
            For rowNum = .Rows.Count To 1 Step -1
                With .Cells(rowNum, 1)
                    numberArray = Split(CStr(.Value), ",")
                    Set numberRange = Range(.Cells, .Offset(UBound(numberArray), 0))
                    
                    If 0 < UBound(numberArray) Then
                        With numberRange
                            .Offset(1, 0).Resize(.Rows.Count - 1, 1).EntireRow.Insert shift:=xlDown
                        End With
                        numberRange.Cells(1, 1).Resize(UBound(numberArray) + 1, 1).Value = Application.Transpose(numberArray)
                    End If
                End With
            Next rowNum
        End With
        
        With dataRange.EntireColumn.Columns(1)
            Set dataRange = Range(dataRange, .Cells(.Rows.Count, 1).End(xlUp))
        End With
        
        With dataRange
            On Error Resume Next
            .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
            On Error GoTo 0
            .Value = .Value
        End With
    End Sub
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    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

  6. #6
    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
    With ThisWorkbook.Sheets("DATA").Range("A:C")
            Set dataRange = Range(.Cells(2, Columns.Count).End(xlToLeft), .Cells(.Rows.Count, 1).End(xlUp))
        End With

  7. #7
    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!

+ 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