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
Row/columnABCDEFG
1Split text in rows
2Splittextinrows
3
4

<tbody>
</tbody>


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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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
Row/columnABCDEFG
1Split text in rows
2Splittextinrows
3
4

<tbody>
</tbody>


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
Row/ColABCDE
1Split text in rows
2Split
3text
4in
5rows

<tbody>
</tbody>
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,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

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