How to sort ascending or descending in multiple entries within one single cell?

  • Thread starter Thread starter dstdst123
  • Start date Start date
D

dstdst123

Hi folks,

Am using Excel 2003... in my cell A1, i typed the following using Alt
+Enter

Orange
Apple
Pear
Banana

How can I sort them (they all inside 1 single cell)?

Thanks a lot.

cheers:)
 
Found this routine in one of these news groups. Neglected to attribute at the
time to originator.

Sub SortCell()

'Sorting cell contents
'You can use the split command to convert the content to an array, then sort
'the array, use the join command to recreate, then place it back in the cell.

Dim i As Long, J As Long
Dim swap1, swap2
Dim varr
varr = Split(ActiveCell, Chr(10)) 'change delimiter if necessary
' peform bubble sort
For i = 0 To UBound(varr) - 1
For J = i + 1 To UBound(varr)
varr(i) = Trim(varr(i))
varr(J) = Trim(varr(J))
If varr(i) > varr(J) Then
swap1 = varr(i)
swap2 = varr(J)
varr(J) = swap1
varr(i) = swap2
End If
Next J
Next i
ActiveCell.Value = Application.Trim( _
Join(varr, " "))
End Sub


Gord Dibben MS Excel MVP
 
Hi,

You can only sort cells but nor cells that have paragraph mark within a cell.

Challa Prabhu
 
Back
Top