Convert coma delimited cell into rows

mender

New Member
Joined
Sep 18, 2006
Messages
3
I have file that was converted into excel spreadsheet from another program. In column B each cell may contain a entry that is comma delimited. I need to convert each cell that has a comma delimited entry to seperate rows under the original cell and to remove the space after the comma.

Example: Before
-------------Column B
Cell 1 Asset Management, Brokerage, Commercial Banking

Example: After
-------------Column B
Cell 1 Asset Management
Cell 2 Brokerage
Cell 3 Commercial Banking
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This macro assumes there won't be any trailing commas:

Code:
Sub CommaSeparatedRows()
Dim strText As String, x As Integer, cell As Range

    Application.ScreenUpdating = False
    ActiveCell.Offset(0, 1).EntireColumn.Insert
    For Each cell In Selection
        strText = cell.Value
        Do While Err = 0
            On Error Resume Next
            x = Application.WorksheetFunction.Find(",", strText)
            If Err = 0 Then
                If Application.CountA(ActiveCell.Offset(0, 1).EntireColumn) = 0 Then
                    cell.Offset(0, 1).Value = Left(strText, x - 1)
                Else
                    cell.Offset(65536 - cell.Row, 1).End(xlUp).Offset(1, 0).Value = Left(strText, x - 1)
                End If
                
                strText = Right(strText, Len(strText) - x)
            Else
                cell.Offset(65536 - cell.Row, 1).End(xlUp).Offset(1, 0).Value = strText
            End If
        Loop
        On Error GoTo 0
    Next cell
    ActiveCell.Offset(0, 1).EntireColumn.AutoFit
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi mender
Welcome to the board

Try this:

Code:
Sub SplitCellsRows()
Dim rC As Range, arr, lRow As Long, lLastRow As Long, i As Integer

lLastRow = Range("B" & Rows.Count).End(xlUp).Row

For lRow = lLastRow To 1 Step -1
    Set rC = Range("B" & lRow)
    If rC <> "" Then
        arr = Split(rC, ",")
        rC = Trim(arr(0))
        For i = 1 To UBound(arr)
            rC.Offset(i).EntireRow.Insert (xlShiftDown)
            rC.Offset(i) = Trim(arr(i))
        Next
    End If
Next

End Sub

Hope this helps
PGC
 
Upvote 0

Forum statistics

Threads
1,212,046
Messages
6,105,586
Members
447,972
Latest member
carrieann

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top