View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Peter Herman Peter Herman is offline
external usenet poster
 
Posts: 10
Default Sorting numbers in a row from small to large

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.