Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I "sort" Worksheet Tabs in my Workbook

Status
Not open for further replies.

Tim58

Technical User
Feb 1, 2004
68
CA
I have 15 Worksheets in my Excel Workbook and I know I can move the tabs around to put them in a desired order. Is there a way I can sort the tabs alphabetically?
 
The easiest way is to download the free ASAP utility addin - available at It's got a ton of useful stuff on it. Quite honestly I don't use it that often, but it's worth keeping around for situations like this. Once installed, all you have to do is go to ASAP Utilities > Sheets > Sort all sheets in alphabetical order.

If you don't want to download anything, then you can use the macro found at

*Disclaimer: I'm not affiliated with ASAP, just a customer.

[tt]-John[/tt]
________________________
To get the best answers fast, please read faq181-2886
 
Try this:

Sub AlphabetizeSheets()
'
' AlphabetizeSheets Macro
' Macro recorded 2/17/2005 by BBottin
'

'
Sheets.Add
ActiveSheet.Move Before:=Sheets(1)
Sheets(1).Select
SheetIndex = 2
Sheets(SheetIndex).Select

On Error Resume Next
While Err = 0
SheetName = ActiveSheet.Name
Sheets(1).Select
Range("a" & SheetIndex & "").Select
ActiveCell = SheetName
SheetIndex = SheetIndex + 1
Sheets(SheetIndex).Select
Wend

Sheets(1).Select
Range("a2").Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

DataSheet = ActiveSheet.Name
Rank = 1
While ActiveCell <> ""
SortSheet = ActiveCell
Sheets("" & SortSheet & "").Select
ActiveSheet.Move After:=Sheets(Rank)
Sheets("" & DataSheet & "").Select
ActiveCell.Offset(1, 0).Activate
Rank = Rank + 1
Wend
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
End Sub
 

And another (I probably got this from this forem in the past)
Code:
Sub SortWorksheets()

Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean

SortDescending = False

If ActiveWindow.SelectedSheets.Count = 1 Then
    FirstWSToSort = 1
    LastWSToSort = Worksheets.Count
Else
    With ActiveWindow.SelectedSheets
        For N = 2 To .Count
            If .Item(N - 1).Index <> .Item(N).Index - 1 Then
                MsgBox "You cannot sort non-adjacent sheets"
                Exit Sub
            End If
        Next N
        FirstWSToSort = .Item(1).Index
        LastWSToSort = .Item(.Count).Index
     End With
End If

For M = FirstWSToSort To LastWSToSort
    For N = M To LastWSToSort
        If SortDescending = True Then
            If UCase(Worksheets(N).name) > UCase(Worksheets(M).name) Then
                Worksheets(N).Move Before:=Worksheets(M)
            End If
        Else
            If UCase(Worksheets(N).name) < UCase(Worksheets(M).name) Then
               Worksheets(N).Move Before:=Worksheets(M)
            End If
        End If
     Next N
Next M

End Sub
 
anotherhiggins

Exactly, I did get it from an old TT thread...and I really can spell forum !!!
 
[lol]

[tt]-John[/tt]
________________________
To get the best answers fast, please read faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top