Note: The other languages of the website are Google-translated. Back to English

Excel: How to split delimited text to rows

Let’s say here is a table with three columns in a worksheet, the first one lists the price levels, the second one lists fruit names with commas delimited in cells, and the third column lists the prices of the fruits. The job is to split the delimited fruit names into rows, and repeat the related price levels and prices rows as below screenshot shown:
doc fill text based on color 1

Here introduce two methods to solve this job.

Split delimited text to rows by using VBA

Split delimited text to rows by using Power Query


Split delimited text to rows by using VBA

Here is a VBA code that can quickly split delimited text to rows.

1. Press Alt + F11 keys to enable the Microsoft Visual Basic for Applications window.

2. Click Insert tab > Module to create a new blank module.

3. Copy and paste below code to the blank module.

VBA: Split delimited text to rows

Public Sub SplitTextInCellsToRows()
'UpdatebyExtendoffice20220622
    Dim xSRg, xIptRg, xCrRg, xRg As Range
    Dim xSplitChar As String
    Dim xArr As Variant
    Dim xFNum, xFFNum, xRow, xColumn, xNum As Integer
    Dim xWSh As Worksheet
    Set xSRg = Application.InputBox("Select a range:", "Kutools for Excel", , , , , , 8)
    If xSRg Is Nothing Then Exit Sub
    xSplitChar = Application.InputBox("Type delimiter:", "Kutools for Excel", , , , , , 2)
    If xSplitChar = "" Then Exit Sub

    Application.ScreenUpdating = False
    xRow = xSRg.Row
    xColumn = xSRg.Column
    Set xWSh = xSRg.Worksheet
    For xFNum = xSRg.Rows.Count To 1 Step -1
        
        Set xRg = xWSh.Cells.Item(xRow + xFNum - 1, xColumn)
        Debug.Print xRg.Address
        xArr = Split(xRg, xSplitChar)
        For xFFNum = LBound(xArr) To UBound(xArr)
            xRg.EntireRow.Copy
            xRg.Offset(1, 0).EntireRow.Insert Shift:=xlShiftDown
            xRg.Worksheet.Cells(xRow + xFNum, xColumn) = xArr(xFFNum)
        Next
        xRg.EntireRow.Delete
    Next
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

4. Press F5 key to click the run button doc fill text based on color 1 to activate the code, a dialog pops out for you to select the column that excludes the header that contains the delimited text needed to be split into rows. Click OK.
doc fill text based on color 1

5. Then the second dialog pops to enter the delimiter you use. Here types comma (,). Click OK.
doc fill text based on color 1

Now the delimited texts have been split into rows and other related columns have been repeated.
doc fill text based on color 1

doc fill text based on color 1  The VBA will change the original data, you should better save a copy of it before.


Split delimited text to rows by using Power Query

If you are in Excel 2013 or later versions, the Power Query will be a good choice for solving this job.

1. Select the data range, to click Data > From Table/Range.
doc fill text based on color 1

2. In the popping Create Table dialog, check My table has headers as you need, and click OK.
doc fill text based on color 1

Then the Power Query Editor window is displayed, and the data has been shown in it.
doc fill text based on color 1

3. Click on the column that you want to split the delimited texts to rows, and click Transform tab > Split Column > By Delimiter.
doc fill text based on color 1

Or you also can select the column and right-click on the column header to choose this feature in the context menu.
doc fill text based on color 1

4. In the Split Column by Delimiter window, choose the delimiter as you need from the Select or enter delimiter section, then choose Each occurrence of the delimiter option, and then expand Advanced options section to choose Rows option. Click OK.
doc fill text based on color 1

Now the delimited texts have been split into rows.
doc fill text based on color 1

5. Then close the window, a dialog pops out, click Keep button.
doc fill text based on color 1

Then a new sheet will be created with the table.
doc fill text based on color 1


Other Operations (Articles)

How to alternate row color based on group in Excel?
In Excel, to color every other row may be easier for most of us, but, have you ever tried to color the rows alternately based on a column value changes – Column A as following screenshot shown, in this article, I will talk about how to alternate row color based on group in Excel.

How To Reduce Excel File Size?
Sometimes, it will take minutes to open or save if the Excel file is too large. For solving this problem, here in this tutorial, it tells you how to reduce the Excel file size by removing the contents or formats which are unnecessary or never used.

Excel: How To Create Or Insert A Bookmark
Have you ever imagined creating or inserting a bookmark for quickly jumping to a specific data range while there is a lot of data in a worksheet or a workbook?

How to apply shading to odd or even (alternative) rows/columns in Excel?
While designing a worksheet, many people tend to apply shading to odd or even (alternative) rows or columns in order to make the worksheet more visual. This article will show you two methods to apply shading to odd or even rows/columns in Excel.



  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns and Keeping Data; Split Cells Content; Combine Duplicate Rows and Sum/Average... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Favorite and Quickly Insert Formulas, Ranges, Charts and Pictures; Encrypt Cells with password; Create Mailing List and send emails...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • Pivot Table Grouping by week number, day of week and more... Show Unlocked, Locked Cells by different colors; Highlight Cells That Have Formula/Name...
kte tab 201905
  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations