Sorting sheets in a book


If the number of tabs in your book approaches several dozen, sooner or later you will want to sort the sheets in the book by placing them in alphabetical order. The standard Excel tools don't allow you to do this, so let's write a simple macro that will do it.

VBA code for the macro

Open the menu Service - Macro - Editor Visual Basic (Tools - Macro - Visual Basic Editor) , insert the VBA module (menu Insert - Module ) and copy go there this text:

Sub SortSheets()
  Dim I As Integer, J As Integer

    For I = 1 To Sheets.Count - 1
        For J = I + 1 To Sheets.Count
            If UCase(Sheets(I).Name) > UCase(Sheets(J).Name) Then
                Sheets(J).Move Before:=Sheets(I)
            End If
        Next J
    Next I
    MsgBox "Tabs were sorted from A to Z"
End Sub

This macro can now be run via the menu Service - Macro - Macros (Tools - Macro - Macros) , and it will quickly sort all the worksheets in the current workbook.

Related Articles:

  • Collection of worksheets
  • Quick switch between worksheets