Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Sort numbers in a cell

已查看 43 次
跳至第一个未读帖子

Wrenn

未读,
2003年8月29日 12:18:242003/8/29
收件人
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]

未读,
2003年8月29日 14:57:352003/8/29
收件人
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

未读,
2003年8月29日 15:00:272003/8/29
收件人
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

未读,
2003年8月29日 15:31:112003/8/29
收件人
ThatWroked. Thank you so much. You have saved me days
of work.
>.
>
0 个新帖子