Text to column but in rows

Gehree

New Member
Joined
Jul 16, 2018
Messages
7
Hi All,

First time on this forum and was hoping to get some help. I am trying to do a text to column but in vertical format instead of having it split horizontally.

For example,
My data now looks something like this.
NameAttributes
TomMale, Teen, Tall, Glasses, Black hair
HenryMale, Adult, Short
ClarissaFemale, Adult
SamMale, Child, Short, Black hair
SarahFemale, Teen, Red hair

<tbody>
</tbody>

I require it to look something like this.
NameAttributes
TomMale
Tom
Teen
TomTall
TomGlasses
TomBlack hair
HenryMale
HenryAdult
HenryShort
ClarissaFemale
ClarissaAdult
SamMale
SamChild
SamShort
SamBlack hair
SarahFemale
SarahTeen
SarahRed hair

<tbody>
</tbody>

Any help would be greatly appreciated!

Thank you!
 
You're very welcome...

Hi Tonyyy,

I just ran the code on a larger sample and noticed something strange, while the code does its function, it leaves a few misaligned gaps in between when there are entries without commas or when there are blanks in between. Here's an example of how it looks.

Before I run the code, it looks like this:
NameAttributes
A1, 2, 3
B4, 5
C6
D7, 8
E
F9
G10, 11

<tbody>
</tbody>













After I run the code, it looks like this.
NameAttributes
A1
A2
A3
B4
B5
6
C6
D7
D8
E
9
F9
G10
G11

<tbody>
</tbody>



























Any idea why it's like this?
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Gehree,

Ah, you've got bad data, and will need to clean it up before running the macro.

jk!

In future though, please try to post a representative data sample in your initial post. This will help you get a better solution sooner rather than later.

Code:
Sub TextToRows()
Application.ScreenUpdating = False
Dim i As Long
Dim arr As Variant

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    arr = Split(Cells(i, 2).Value, ",")
    If UBound(arr) > 0 Then
        Rows(i + 1 & ":" & i + UBound(arr)).Insert
        Cells(i, 1).Resize(UBound(arr) + 1, 1) = Cells(i, 1).Value
        Cells(i, 2).Resize(UBound(arr) + 1, 1) = Application.Transpose(arr)
    End If
Next i
End Sub

The revised code accommodates single and blank entries.

Cheers,

tonyyy
 
Upvote 0
Gehree,

Ah, you've got bad data, and will need to clean it up before running the macro.

jk!

In future though, please try to post a representative data sample in your initial post. This will help you get a better solution sooner rather than later.

Code:
Sub TextToRows()
Application.ScreenUpdating = False
Dim i As Long
Dim arr As Variant

For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
    arr = Split(Cells(i, 2).Value, ",")
    If UBound(arr) > 0 Then
        Rows(i + 1 & ":" & i + UBound(arr)).Insert
        Cells(i, 1).Resize(UBound(arr) + 1, 1) = Cells(i, 1).Value
        Cells(i, 2).Resize(UBound(arr) + 1, 1) = Application.Transpose(arr)
    End If
Next i
End Sub

The revised code accommodates single and blank entries.

Cheers,

tonyyy

Hi Tonyyy,

Hahah yes, in fact you are right, I do have bad data and I'm in the midst of cleaning it but I got 7000 entries with 50 columns of attributes to work with so it's taking me a long time to do it. In any case, it's working perfectly now. You have no idea how much time you just saved for me!

Thank you so much!(Again)

Cheers,
Gehree
 
Upvote 0

Forum statistics

Threads
1,215,262
Messages
6,123,939
Members
449,134
Latest member
NickWBA

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