Sorting Spreadsheets


Posted by jennifer on December 13, 2001 8:36 PM

I just got asked this question, and have no clue...

Is there anyway to alphabetically sort worksheets within a workbook?



Posted by DaK on December 13, 2001 8:40 PM

Use this code and attach it to a button. The only thing is that sheets with just a number will come first alphabetically.

Public Sub sortsheets()
'sort the workbook sheets

Dim iCount As Integer
Dim i As Integer
Dim j As Integer

On Error Resume Next
iCount = Sheets.Count
For i = 1 To iCount - 1
For j = i + 1 To iCount
If Sheets(j).Name < Sheets(i).Name Then
Sheets(j).Move before:=Sheets(i)
End If
Next j
Next i

End Sub