Sort EXCEL sheets into alphabetical order

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a workbook with 50 sheets (1 for each employee).

How can I get Excel to sort these into alphabetical order ?

(From (e-mail address removed))
 
This macro should do it.

Sub SortSheets()

Dim sht As Worksheet
Dim mySht As Worksheet
Dim i As Integer
Dim endRow As Long
Dim shtNames As Range
Dim Cell As Range

Set mySht = Sheets.Add
mySht.Move before:=Sheets(1)

For i = 2 To Sheets.Count
mySht.Cells(i - 1, 1).Value = Sheets(i).Name
Next i

endRow = mySht.Cells(Rows.Count, 1).End(xlUp).row
Set shtNames = mySht.Range(Cells(1, 1), Cells(endRow, 1))

shtNames.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlNo, OrderCustom:=1

i = 2
For Each Cell In shtNames
Sheets(Cell.Value).Move before:=Sheets(i)
i = i + 1
Next Cell

Application.DisplayAlerts = False
mySht.Delete
Application.DisplayAlerts = True

End Sub


Regards
Rowan
 
KymY said:
I have a workbook with 50 sheets (1 for each employee).

How can I get Excel to sort these into alphabetical order ?

(From (e-mail address removed))
Thanks, mate - have pasted the script into my Lotus Organizer Tips notepad
 

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

Similar Threads


Back
Top