Hi, Searching around this morning trying to find something that may work, I need to sort my worksheet tabs from 1 to 62 so I tried many scripts but the sort is always in the wrong order. The tab names are 1,2,3 all the way to 62. So I thought I could put these in an array and then sort the array then sort the tabs by the sorted array. Just not working?
could someone help with this script below or maybe another idea would work.
Thank You, Mike
Sub SortWS3()
Dim Ndx As Long
Dim i
ReDim SNarray(1 To Sheets.Count)
For i = 1 To Sheets.Count
SNarray(i) = ThisWorkbook.Sheets(i).Name
'Debug.Print SNarray(i)
Next
Stop
Call BubbleSort(SNarray)
For Ndx = UBound(SNarray) To LBound(SNarray) Step -1
Worksheets(SNarray(Ndx)).Move before:=Worksheets(1)
Next Ndx
End Sub
Sub BubbleSort(ByRef lngArray() As Long)
Dim iOuter As Long
Dim iInner As Long
Dim iLBound As Long
Dim iUBound As Long
Dim iTemp As Long
iLBound = LBound(lngArray)
iUBound = UBound(lngArray)
'Which bubbling pass
For iOuter = iLBound To iUBound - 1
'Which comparison
For iInner = iLBound To iUBound - iOuter - 1
'Compare this item to the next item
If lngArray(iInner) > lngArray(iInner + 1) Then
'Swap
iTemp = lngArray(iInner)
lngArray(iInner) = lngArray(iInner + 1)
lngArray(iInner + 1) = iTemp
End If
Next iInner
Next iOuter
End Sub
Bookmarks