I have this code that I pieced together meant to sort sheets by name and number. Sheets with string names work fine, but numeric labels sort funny ex: 1, 10, 12, 2, 20... kind of sorted, but not really. I believe the bug is in the BubbleSort sub.
...Code... creates single dim array with sheet labels in it
Call BubbleSort(SheetNames)
'Move Sheet Names accordingly
For i = 1 To SheetCount
ActiveWorkbook.Sheets(SheetNames(i)).Move _
Before:=ActiveWorkbook.Sheets(i)
Next i
'Reactivate original sheet
OldActive.Activate
End Sub
Sub BubbleSort(List() As String)
Dim First As Integer, Last As Integer
Dim i As Integer, j As Integer
Dim Temp As String
First = LBound(List)
Last = UBound(List)
'Dim and assigning variables
For i = First To Last - 1 'Sorts all sheets into new array
For j = i + 1 To Last
If List(i) > List(j) Then
Temp = List(j)
List(j) = List(i)
List(i) = Temp
End If
Next j 'Go to next j
Next i 'Go to next i
End Sub
...Code... creates single dim array with sheet labels in it
Call BubbleSort(SheetNames)
'Move Sheet Names accordingly
For i = 1 To SheetCount
ActiveWorkbook.Sheets(SheetNames(i)).Move _
Before:=ActiveWorkbook.Sheets(i)
Next i
'Reactivate original sheet
OldActive.Activate
End Sub
Sub BubbleSort(List() As String)
Dim First As Integer, Last As Integer
Dim i As Integer, j As Integer
Dim Temp As String
First = LBound(List)
Last = UBound(List)
'Dim and assigning variables
For i = First To Last - 1 'Sorts all sheets into new array
For j = i + 1 To Last
If List(i) > List(j) Then
Temp = List(j)
List(j) = List(i)
List(i) = Temp
End If
Next j 'Go to next j
Next i 'Go to next i
End Sub