Macro for sorting worksheets alphabetically by name


Posted by Garland on December 23, 2000 11:47 PM

Can anyone suggest a macro to sort the worksheets in an
Excel workbook alphabetically by sheet name?

TIA

Garland

Posted by Aladin Akyurek on December 24, 2000 12:31 AM

See

http://www.cpearson.com/excel/sortws.htm

Aladin

Posted by Dave on December 24, 2000 11:36 AM

Hi Garland

Here's the code for one I keep in my personal macro workbook.

Sub SortSheets_Click()
Dim i As Integer, ii As Integer
Dim ShtName As String
If ActiveWorkbook.Sheets.Count > 1 Then
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets.Add().Name = "SheetNames"
If ActiveSheet.Name <> "SheetNames" Then ActiveSheet.Delete
With ActiveWorkbook.Sheets("SheetNames")
.Columns(1).Clear
For i = 1 To ActiveWorkbook.Sheets.Count
.Cells(i, 1) = Sheets(i).Name
Next

.Columns(1).Sort Key1:=.Cells(1, 1), Order1:=xlAscending

For ii = i - 1 To 1 Step -1
ShtName = .Cells(ii, 1)
ActiveWorkbook.Sheets(ShtName).Move Before:=ActiveWorkbook.Sheets(1)
Next
End With
Sheets("SheetNames").Delete
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End If
End Sub


Hope it helps

Dave

OzGrid Business Applications



Posted by Garland on December 24, 2000 11:51 PM

Thanks to both of you guys.... I have what I needed, now.