Alphabetizing The Worksheets

fdegree

New Member
Joined
Jul 13, 2008
Messages
27
As you all know, when you open a workbook, there are tabs in the lower left corner that show the names of each worksheet within that workbook. My question is…How can I sort these worksheets (tabs) into alphabetical order?


Thanks...
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this macro:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Rich (BB code):
<o:p></o:p>
Rich (BB code):
Rich (BB code):
Sub SortTabs()<o:p></o:p>
Dim CheckStr1 As String, CheckStr2 As String<o:p></o:p>
Dim sh As Worksheet<o:p></o:p>
Dim SheetNames() As String<o:p></o:p>
Dim NoOfSheets As Long<o:p></o:p>
Dim c As Long, d As Long<o:p></o:p>
Dim Anyswaps As Boolean<o:p></o:p>
NoOfSheets = ThisWorkbook.Sheets.Count<o:p></o:p>
ReDim SheetNames(NoOfSheets)<o:p></o:p>
If NoOfSheets > 1 Then<o:p></o:p>
    c = 1<o:p></o:p>
    For Each sh In ThisWorkbook.Worksheets<o:p></o:p>
        SheetNames(c) = sh.Name<o:p></o:p>
        c = c + 1<o:p></o:p>
    Next sh<o:p></o:p>
    Do<o:p></o:p>
        Anyswaps = False<o:p></o:p>
        For c = 1 To NoOfSheets - 1<o:p></o:p>
            If SheetNames(c) > SheetNames(c + 1) Then<o:p></o:p>
                SheetNames(0) = SheetNames(c)<o:p></o:p>
                SheetNames(c) = SheetNames(c + 1)<o:p></o:p>
                SheetNames(c + 1) = SheetNames(0)<o:p></o:p>
                Anyswaps = True<o:p></o:p>
            End If<o:p></o:p>
        Next c<o:p></o:p>
    Loop Until Anyswaps = False<o:p></o:p>
    For d = 1 To NoOfSheets<o:p></o:p>
        For c = NoOfSheets To 2 Step -1<o:p></o:p>
            Sheets(SheetNames(c)).Move after:=Sheets(SheetNames(c - 1))<o:p></o:p>
        Next c<o:p></o:p>
    Next d<o:p></o:p>
End If<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
 
Upvote 0
This should work also:

Code:
Sub sortWS()
Dim ws As Worksheet
Sheets.Add after:=Sheets(Sheets.Count)
Set ws = ActiveSheet
    For i = 1 To Sheets.Count - 1
        ws.Cells(i, 1).Value = Sheets(i).Name
    Next i
    ws.Range("A1:A" & Sheets.Count - 1).Sort key1:=Range("A1")
    For i = 1 To Sheets.Count - 1
        Sheets(ws.Cells(i, 1).Value).Move Before:=Sheets(i)
    Next i
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End Sub
 
Upvote 0
Thank you everyone...it's working great.

Kind of interesting how there is more than 1 approach to solving these issues. At least it is interesting to me...I don't know anything about it.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top