How to split data in rows within a cell

kimsa

New Member
Joined
Feb 26, 2016
Messages
15
I have this data within a cell cars; boats; autos; tractors; buses

I want to sort in alpha order and split the data so each term is on the next line so to look like this within the cell

autos
boats
buses
cars
tractors
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
How about
Code:
Sub kimsa()
   Dim Cl As Range
   Dim Lst As Object
   Dim Sp As Variant
   Dim i As Long
   
   Set Lst = CreateObject("system.collections.arraylist")
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Sp = Split(Cl.Value, "; ")
      For i = 0 To UBound(Sp)
         Lst.Add CStr(Sp(i))
      Next i
      Lst.Sort
      Cl.Value = Join(Lst.toarray, Chr(10))
      Lst.Clear
   Next Cl
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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