Worksheet order

G

Guest

I have a workbook with about 20 worksheets. I would like to organize the
worksheets alphabetically by their tab name. Is there some way to do that
other than manually move the worksheets to the order I want? Thanks.
 
D

Don Guillett

Here are a couple of macros for that

Sub sortworksheets()
Dim Cnt As Integer
Dim n As Integer
Dim m As Integer
Dim WS As Worksheet
Set WS = ActiveSheet
Cnt = ActiveWorkbook.Worksheets.COUNT
For m = 1 To Cnt
For n = m To Cnt
If UCase(Worksheets(n).Name) < UCase(Worksheets(m).Name) Then
Worksheets(n).Move Before:=Worksheets(m)
End If
Next n
Next m
WS.Activate
End Sub

Sub sortworksheetsA()
Dim m As Integer
On Error GoTo EndOfMacro
Application.ScreenUpdating = False
Cnt = ActiveWorkbook.Worksheets.COUNT
For m = 1 To Cnt
For n = m To Cnt
If UCase(Worksheets(n).Name) < UCase(Worksheets(m).Name) Then
Worksheets(n).Move Before:=Worksheets(m)
End If
Next n
Next m
EndOfMacro:
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top