Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sort numbers in a cell

43 views
Skip to first unread message

Wrenn

unread,
Aug 29, 2003, 12:18:24 PM8/29/03
to
Is there a way for excel to sort within a cell, not a row
or column. I have a spreadsheet with lots of numbers in
cells and I would like the numbers to be in order withing
the cell.

Thanks for any help you may provide.

greg mansius [MSFT]

unread,
Aug 29, 2003, 2:57:35 PM8/29/03
to
Wrenn,

You probably need to build a formula in the column next to the data and
manipulat the data within the formula. Then, when you have the formula
working you can do a Copy - Paste Special (Values) on top of the formula to
keep the results but remove the formula.

Do you have an example of your data and how you want it to look?

--
Greg Mansius [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.

"Wrenn" <goplayou...@yahoo.com> wrote in message
news:0dc101c36e49$2bd7b250$a501...@phx.gbl...

J.E. McGimpsey

unread,
Aug 29, 2003, 3:00:27 PM8/29/03
to
You'll have to use a macro.

One way, as an example: Assume your numbers are separated by commas,
then select the cells you want to sort and run this:

Public Sub SortNumbersWithinCells()
Const DELIM As String = ","
Dim sIn As String
Dim sArr As Variant
Dim sOut As String
Dim temp As Double
Dim change As Boolean
Dim i As Integer
Dim cell As Range

For Each cell In Selection
sIn = cell.Text
sArr = Split(sIn, DELIM)
Do
change = False
For i = 0 To UBound(sArr) - 1
If sArr(i) > sArr(i + 1) Then
temp = sArr(i)
sArr(i) = sArr(i + 1)
sArr(i + 1) = temp
change = True
End If
Next i
Loop Until change = False
For i = 0 To UBound(sArr)
sOut = sOut & DELIM & sArr(i)
Next i
cell.Value = Mid(sOut, 2)
sOut = Empty
Next cell
End Sub

Change DELIM if you have a different separator

Note: if using XL97/98/01/v.X, Split() doesn't exist. You can roll
your own or use the routine found at

http://support.microsoft.com/default.aspx?scid=kb;en-us;188007

Note also: this routine has no error handling - so it assumes that
all your cells will be well-formed.

In article <0dc101c36e49$2bd7b250$a501...@phx.gbl>,

Wrenn

unread,
Aug 29, 2003, 3:31:11 PM8/29/03
to
ThatWroked. Thank you so much. You have saved me days
of work.
>.
>
0 new messages