tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
I would like to sort the digits in a cell in ascending order.
So for example, I want:
to be converted to:
I found this code:
and I call it as follows:
but it crashes on this line:
with an error message:
I typed this into the Immediate Window:
and it retuned blank, so I added the CLng and the same error message appeared.
Same error for:
Can someone point out what's wrong.
Thanks
So for example, I want:
Code:
6,4,5
to be converted to:
Code:
4,5,6
I found this code:
Code:
https://www.mrexcel.com/board/threads/vba-sort-alphanumeric-comma-delimited-text-in-a-cell.1135586/
and I call it as follows:
Code:
Dim a As Variant
a = SortCSVString(Sheet1.Cells(1, 1).Value2
but it crashes on this line:
Code:
Sub SortArray(ByRef arr() As String)
Dim temp As Variant
Dim i As Long
Dim j As Long
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If CLng(Mid(Trim(arr(i)), 2)) > CLng(Mid(Trim(arr(j)), 2)) Then '***** CRASHES HERE
temp = arr(i)
arr(i) = arr(j)
arr(j) = temp
End If
Next j
Next i
End Sub
with an error message:
Code:
Run-time error '13':
Type mismatch
I typed this into the Immediate Window:
Code:
?mid(Trim(arr(i)),2)
and it retuned blank, so I added the CLng and the same error message appeared.
Same error for:
Code:
?mid(Trim(arr(j)),2)
Can someone point out what's wrong.
Thanks