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

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...