Split Text in Rows

IoanZ

Board Regular
Joined
Mar 2, 2018
Messages
51
Hello to everyone.

I use this code to split text in to separate colums
[TABLE="width: 500"]
<tbody>[TR]
[TD]Row/column[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Split text in rows[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]Split[/TD]
[TD]text[/TD]
[TD]in[/TD]
[TD]rows[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Sub SplitTextColumn()
Dim i As Long
Dim vA As Variant
For i = 1 To Range("A1").Rows.Count
vA = Split(Range("A1").Resize(1).Offset(i - 1), " ")
Range("B2").Resize(1, UBound(vA) + 1) = vA
Next
End Sub

I want to know which is vba modification to split the text from Cell A1 into separate rows?

Thank's a lot
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Range("B2").Resize(UBound(vA) + 1, 1) = Application.Transpose(vA)
 
Upvote 0
Hello to everyone.

I use this code to split text in to separate colums
[TABLE="width: 500"]
<tbody>[TR]
[TD]Row/column[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Split text in rows[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]Split[/TD]
[TD]text[/TD]
[TD]in[/TD]
[TD]rows[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Sub SplitTextColumn()
Dim i As Long
Dim vA As Variant
For i = 1 To Range("A1").Rows.Count
vA = Split(Range("A1").Resize(1).Offset(i - 1), " ")
Range("B2").Resize(1, UBound(vA) + 1) = vA
Next
End Sub

I want to know which is vba modification to split the text from Cell A1 into separate rows?

Thank's a lot
This is why single examples are not much help. Do you have data in cells A2, A3, etc.? While your loop's upper limit evaluates to 1 (which means only cell A1 is being processed), your use of a loop kind of suggests you have other data. So, do you? If so, how did you want the output to run downward... cell A1's split apart text followed by cell A2's split apart text etc.? Please clarify how much data you have and how it is laid out.
 
Upvote 0
[TABLE="width: 500"]
<tbody>[TR]
[TD]Row/Col[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Split text in rows[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]Split[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]text[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD]in [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD]rows[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I want to obtain a vertical split of the text.

Works perfectly with

Sub SplitTextColumn()
Dim i As Long
Dim vA As Variant
For i = 1 To Range("A1").Rows.Count
vA = Split(Range("A1").Resize(1).Offset(i - 1), " ")
Range("B2").Resize(1, UBound(vA)+1,1) = Application.Transpose(vA)
Next
End Sub

Thank's a lot guys :)
 
Upvote 0
Using Power Query, here is an alternate solution:

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    SplitColumn = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1")
in
    SplitColumn

Steps taken in above Mcode
1. Import Table to PQ
2. Select Split Column
3. Select Rows
4. Close and Load to Excel

PQ is available in all versions of Excel beginning with 2010.
 
Upvote 0
And here is an alternate VBA solution that does not use any loops...
Code:
Sub SplitTextDownward()
  Dim Arr As Variant
  Arr = Application.Transpose(Split(Range("A1").Value))
  Range("B2").Resize(UBound(Arr)) = Arr
End Sub
Note: You can change the location of the output by changing the red highlighted B2 to a cell address of your own choosing (even including A1 if you would like to overwrite your original data).
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,712
Members
452,995
Latest member
isldboy

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