Code:
Sub Sorter()
Dim arrToSort() As String
Dim lngIndex As Long
arrToSort = Split("This string is short," _
& "xxxxxxxxxx," _
& "aaaaaaaaaa," _
& "This string is kinda big," _
& "This string is a really big one," _
& "This string is medium", ",")
Sort_Bubble arrToSort
For lngIndex = 0 To UBound(arrToSort)
Debug.Print arrToSort(lngIndex)
Next lngIndex
End Sub
Public Sub Sort_Bubble(arrSort As Variant)
Dim lngIndex As Long
Dim lngNext As Long
Dim strTemp As String
For lngIndex = LBound(arrSort) To UBound(arrSort) - 1
For lngNext = lngIndex + 1 To UBound(arrSort)
If Len(arrSort(lngIndex)) > Len(arrSort(lngNext)) Then
strTemp = arrSort(lngNext)
arrSort(lngNext) = arrSort(lngIndex)
arrSort(lngIndex) = strTemp
ElseIf Len(arrSort(lngIndex)) = Len(arrSort(lngNext)) Then
'If string lenght is equal sort alphabetically.
If arrSort(lngIndex) > arrSort(lngNext) Then
strTemp = arrSort(lngNext)
arrSort(lngNext) = arrSort(lngIndex)
arrSort(lngIndex) = strTemp
End If
End If
Next lngNext
Next lngIndex
End Sub