I am trying to figure out how to sort an array numerically. I have no problem getting it to work alphabetically; but numerically, it does not seem to work.
I have below, for example, a list of four numbers divided by commas, but I can't understand why "actual" at the bottom of this code does not give "3, 4, 5, 11" instead of "11, 3, 4, 5". Many thanks in advance for any help on this matter!
Dim actual As String
Dim arr As Variant
Dim overall As String
Dim strTemp As Long
Dim i As Long
Dim j As Long
Dim lngMin As Long
Dim lngMax As Long
overall = "3, 4, 11, 5"
arr = Split(overall, ", ")
lngMin = LBound(arr)
lngMax = UBound(arr)
For i = lngMin To lngMax - 1
For j = i To lngMax
If arr(i) > arr(j) Then
strTemp = arr(j)
arr(j) = arr(i)
arr(i) = strTemp
End If
Next j
Next i
For i = 0 To UBound(arr)
actual = Join(arr, ", ")
Next i