I have a column of data which has numbers and text in each cell, separated by a comma. I found a UDF in another forum (see code below) which sort of does the job but not quite. For example:
Original cell:
84,86,NA,268,277,400,411,42,120,244,346
UDF result:
120, 244, 268, 277, 346, 400, 411, 42, 84, 86, NA
Desired result:
42, 84, 86, 120, 244, 268, 277, 346, 400, 411, NA
I was wondering if someone could help me fix this code. Thank you much. Best Wishes Manoj
See the code for the UDF i found in another forum
Function StrSort(ByVal sInp As String, _
Optional bDescending As Boolean = False) As String
' sorts a comma-delimited string
Dim asSS() As String ' substring array
Dim sSS As String ' temp string for exchange
Dim n As Long
Dim i As Long
Dim j As Long
asSS = Split(sInp, ",")
n = UBound(asSS)
For i = 0 To n
asSS(i) = Trim(asSS(i))
Next
If n < 1 Then
StrSort = sInp
Else
For i = 0 To n - 1
For j = i + 1 To n
If (asSS(j) < asSS(i)) Xor bDescending Then
sSS = asSS(i)
asSS(i) = asSS(j)
asSS(j) = sSS
End If
Next j
Next i
StrSort = Join(asSS, ", ")
End If
End Function