Using a Macro to Split a Cell into Multiple Rows in Excel – 8 Steps

This is an overview:

Excel Macro to Split a Cell into Multiple Rows


Step 1 – Open the VBA Editor in Excel

  • Select the cell containing the data you want to split, here B2 .
  • Press ALT+F11 to open the VBA window.
  • Select Insert >> Module.

Excel Macro to Split a Cell into Multiple Rows


Step 2 – Create a Sub Procedure

Sub SplitCell()

End Sub

Step 3 – Declare the Necessary Variables

Sub SplitCell()
Dim Cell, SplitCell() As String
End Sub
The Cell variable takes the value of the active cell. The SplitCell() variable stores the array of rows in which data will be split.

Step 3 – Copy the Data to a New Cell

Sub SplitCell()
Dim Cell, SplitCell() As String
ActiveCell.Copy ActiveCell.Offset(2, 0)
End Sub

ActiveCell.Copy copies the data from the currently active cell.

ActiveCell.Offset(2, 0) is the destination cell: 2 rows below the active cell.


Step 4 – Select the New Cell

Sub SplitCell()
Dim Cell, SplitCell() As String
ActiveCell.Copy ActiveCell.Offset(2, 0)
ActiveCell.Offset(2, 0).Select
End Sub
ActiveCell.Offset(2, 0).Select activates the new cell (data in the original cell remains unchanged).

Step 5 – Set the Value of the Variables

Sub SplitCell()
Dim Cell, SplitCell() As String
ActiveCell.Copy ActiveCell.Offset(2, 0)
ActiveCell.Offset(2, 0).Select
Cell = ActiveCell.Value
SplitCell = Split(Cell, ",")
End Sub

Cell = ActiveCell.Value specifies that the Cell variable takes the value of the new active cell.

SplitCell = Split(Cell, “,”) splits the value stored in the Cell variable considering the comma (,) as the split criteria. You can use other delimiters (. ; / ) inside the double quotes (“ ”).


Step 6 – Using a For Loop to Split Data

Sub SplitCell()
Dim Cell, SplitCell() As String
ActiveCell.Copy ActiveCell.Offset(2, 0)
ActiveCell.Offset(2, 0).Select
Cell = ActiveCell.Value
SplitCell = Split(Cell, ",")
For i = 0 To UBound(SplitCell)
Next i
End Sub

The For Loop splits the data whenever a comma is found.

UBound(SplitCell) refers to the largest possible size of the SplitCell array.


Step 7 – Filling Rows with the Split Data

Sub SplitCell()
Dim Cell, SplitCell() As String
ActiveCell.Copy ActiveCell.Offset(2, 0)
ActiveCell.Offset(2, 0).Select
Cell = ActiveCell.Value
SplitCell = Split(Cell, ",")
For i = 0 To UBound(SplitCell)
ActiveCell.Offset(i, 0).Value = SplitCell(i)
Next i
End Sub
ActiveCell.Offset(i, 0).Value = SplitCell(i) returns the value of each row in the SplitCell array.

Step 8 – Run the VBA Code

  • Keep the cursor in the code and press F5 to run it.

Data in B2 will split into multiple rows as shown below:

Read More: How to Split One Cell into Two in Excel


How to Split Data from One Cell into Multiple Rows in Excel – 2 Methods

Method 1 – Split a Cell into Multiple Rows using the Text to Columns & Paste Special in Excel

Steps

  • Select B2 (the cell containing the data you want to split).
  • Select Text to Columns in the Data tab.

  • Select Delimited.
  • Click Next.

  • Check Comma as Delimiters and click Next.

  • Keep General in Column data format.
  • Click the upward arrow in Destination and choose B4 (to get the split data).
  • Click Finish.

Split Data from One Cell into Multiple Rows with Text to Columns & Paste Special in Excel

Data in B2 is split into multiple columns:

  • Copy C4:M4 and paste it as Transpose in B5.

Split Data from One Cell into Multiple Rows with Text to Columns & Paste Special in Excel

  • Delete the helper cells.

This is the output.

Read More: How to Split a Single Cell in Half in Excel


Method 2 – Split a Cell into Multiple Rows using the Power Query in Excel

Steps

  • Select the cell containing the data to split, here B2.
  • Select Data >> From Table/Range.

  • Click OK to create an Excel Table.

  • In the Power Query Editor, select Split Column >> By Delimiter in the Home tab.

  • Choose Comma as delimiter.
  • Select Each occurrence of the delimiter.
  • Choose Rows in Advanced options.
  • Click OK.

You will see a preview of the split data.

  • Select Close & Load >> Close & Load To.

Split Data from One Cell into Multiple Rows with Power Query in Excel

  • Select Table and Existing Worksheet.
  • Click the upward arrow to select B5 (to get the split data).
  • Click OK.

  • The following image will be displayed.

  • Click OK.

This is the output.

Read More: How to Split Cell by Delimiter Using Excel Formula


Things to Remember

  • You may need to press CTRL+SHIFT+Enter to apply the formula in the second method.

Download Practice Workbook

Download the practice workbook.


Further Readings

Get FREE Advanced Excel Exercises with Solutions!
Md. Shamim Reza
Md. Shamim Reza

Md. Shamim Reza, a marine engineer with expertise in Excel and a fervent interest in VBA programming, sees programming as a time-saving tool for data manipulation, file handling, and internet interaction. His diverse skill set encompasses Rhino3D, Maxsurf C++, AutoCAD, Deep Neural Networks, and Machine Learning. He holds a B.Sc in Naval Architecture & Marine Engineering from BUET and has transitioned into a content developer role, generating technical content focused on Excel and VBA. Beyond his professional pursuits,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo