View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Peo Sjoblom Peo Sjoblom is offline
external usenet poster
 
Posts: 3,268
Default Sorting numbers in a row from small to large

No, you would need code for this, if there would be a formula it would be a
very complicated
array formula and with 45000 rows the file would choke on itself. Array
formulas are notoriously slow.


You might want to try another method, first copy this particular column to a
new workbook so you don't do anything to the original, select the column and
do datatext to columns, select delimited click next and select comma as
delimiter and then click finish. Now all these values would be in different
columns, assume they start in A1, in other sheet put this in A1


=SMALL(Sheet1!1:1,COLUMNS($A$1:A1))


copy down 45000 rows and then copy across as many columns as needed


Finally put them together from a third sheet


=Sheet2!A1&", "&Sheet2!B1&", "&Sheet2!C1&", "&Sheet2!D1&", "&Sheet2!E1


then copy down 45000 rows and paste special as values


It might help it might not, it all depends on how many values there are in
your column,
if it's always 5 values with 5 commas the above should work


May I ask what would produce such a beast as your file and why you would
want to sort it?




--
Regards,

Peo Sjoblom

"Peter Herman" wrote in message
...
Thanks Peter,
Unfortunately, I am not that sophistocated. Is there not a function or
formula that I could use?

"barnabel" wrote:

Here is a bit of code. modify it as you wish. It starts are row 1 and
runs
until it finds 4 consective empty rows. It uses a very basic sort but if
you
have less than 10 values on a row it shouldn't matter.

Peter Richardson

Option Explicit

Sub sortnum()
Dim currRow As Long
Dim blankCount As Integer
Dim acell() As String


currRow = 1
blankCount = 0
While blankCount < 5
If (IsEmpty(Cells(currRow, 1))) Then
blankCount = blankCount + 1
Else
blankCount = 0
acell = Split(Cells(currRow, 1), ",")
sortvals acell

Cells(currRow, 1) = Join(acell, ",")
End If
currRow = currRow + 1
Wend

End Sub

Sub sortvals(vals() As String)
Dim donesort As Boolean
Dim i As Integer
Dim holder As String

donesort = False
While Not donesort
donesort = True
For i = LBound(vals) To UBound(vals) - 1
If (CInt(vals(i)) CInt(vals(i + 1))) Then
holder = vals(i)
vals(i) = vals(i + 1)
vals(i + 1) = holder
donesort = False
End If
Next
Wend

End Sub


"Peter Herman" wrote:

Hi there,
I have a column of numbers separated by commas that is about 45,000
rows
long. I would like to sort the numbers in each individual row from
small to
large.
In other words my data looks like this:

column A
17,1,36,98,62
56,94,12,24
and so on...all the way down and I would like it to look like this:

Column A
1,17,36,62,98
12,24,56,94

Thanks to anyone who helps me.