View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
John[_141_] John[_141_] is offline
external usenet poster
 
Posts: 14
Default [Q] How to sort tabs in order of CodeName

Is there a way in VBA to sort the worksheets/tabs in the order of each
worksheet's CodeName? The code below sorts the sheets in alphabetical
order, but how can change it to sort via CodeName?

Sub SortWorksheets()
' sort worksheets in a workbook in ascending order
Dim sCount As Integer, i As Integer, j As Integer
Application.ScreenUpdating = False
sCount = Sheets.Count
If sCount = 1 Then Exit Sub
For i = 1 To sCount - 1
For j = i + 1 To sCount
If Sheets(j).Name < Sheets(i).Name Then
Sheets(j).Move Befo=Sheets(i)
End If
Next j
Next i
End Sub