View Single Post
 
Old 12-04-2014, 07:25 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote