Sorting sheets

G

Guest

Hi All,
I have a workbook with several sheets. Each sheet is named by an employee ID
number. I want to sort the sheets according to the position of each group of
employee.
Is there a way to sort sheets? (A-Z or customize)
Thanks in advance
 
A

Ardus Petus

Sub sortsheets()
'Re-Sort sheet names
' Thanks to McRitchie & Bill Manville
Dim iSheet As Integer
Dim iBefore As Integer

For iSheet = 1 To Worksheets.Count
For iBefore = 1 To iSheet - 1
If UCase(Sheets(iBefore).Name) > UCase(Sheets(iSheet).Name) Then
Sheets(iSheet).Move before:=Sheets(iBefore)
Exit For
End If
Next iBefore
Next iSheet
End Sub

HTH
 
A

Ardus Petus

That was an alpha sort.
For a numeric sort:

'-------------------------------------------------------------------------------
Sub sortsheets()
'Re-Sort sheet names
' Thanks to McRitchie & Bill Manville
Dim iSheet As Integer
Dim iBefore As Integer

For iSheet = 1 To Worksheets.Count
For iBefore = 1 To iSheet - 1
If CInt(Sheets(iBefore).Name) > CInt(Sheets(iSheet).Name) Then
Sheets(iSheet).Move before:=Sheets(iBefore)
Exit For
End If
Next iBefore
Next iSheet
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