How to sort worksheets in alphabetical order in Excel 2016 using VBA Code?

There are times when you wish to sort your worksheet tabs in excel in alphabetical order so that its easier for you to navigate and find the required information. You can sort them by dragging and drooping them in the tab at the bottom of the workbook but this would be a time consuming one. Alternatively , you can achieve the same thing quickly using the VBA Code.

How to sort worksheets in alphabetical order in Excel 2016 using VBA Code?

1. Press the keyboard shortcut key Alt + F11 to display the “Microsoft Visual Basic for Applications” window.
2. Navigate to the Insert menu and click “Module” menu and then paste the below VBA code to the module window and press F5 to run it.

image

Sub Sort()
For i = 1 To Sheets.Count
      For j = 1 To Sheets.Count - 1
            If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
               Sheets(j).Move After:=Sheets(j + 1)
            End If
      Next j
   Next i
End Sub

This should sort the worksheets in the workbook in alphabetical order (ascending order).

image

Leave a Reply