Microsoft Excel – How to Sort Worksheets in Alphabetical Order



If you’re working on a Microsoft Excel worksheet and you decide that you would want the tabs to be in alphabetical order (for whatever reason that may be), then what would you normally do? Check each one and do a click-and-drag for each of those tabs? While that may seem to be a prime idea if you’ve only got a few tabs, but what if you have 10, or perhaps even 50 tabs in a single worksheet? Then just by doing a click-and-drag motion for each one of them. This can take all day! But you don’t have to do this as there is an easier way to accomplish this. Read on to find out how to sort the Excel worksheet tabs in alphabetical order.

Microsoft Excel - How to Sort Worksheets in Alphabetical Order

Easily Sorting Worksheet Tabs in Alphabetical Order in Microsoft Excel

Step 1 – To begin, start by opening up the Microsoft Excel file that you want to edit (if you haven’t already). Once it opens up properly, press the Alt + F11 on your keyboard and this will open up the Microsoft Visual Basic for Applications (VBA) editor. If this is the first time you’re accessing this portion of the program, then don’t be alarmed as to what you’re about to do next.

Step 2 – Once the VBA editor opens up, head to Insert, and then to Module. Since the Microsoft Excel program has no direct way to sort the tabs in alphabetical order, you would need to do some coding. But you don’t have to worry about the code, as it is already provided from the guys at Microsoft themselves. Just copy-and-paste the following code into the module window:

Sub Sort_Active_Book()

Dim i As Integer

Dim j As Integer

Dim iAnswer As VbMsgBoxResult

‘ Prompt the user as which direction they wish to

‘ sort the worksheets.

iAnswer = MsgBox(“Sort Sheets in Ascending Order?” & Chr(10) _

& “Clicking No will sort in Descending Order”, _

vbYesNoCancel + vbQuestion + vbDefaultButton1, “Sort Worksheets”)

For i = 1 To Sheets.Count

For j = 1 To Sheets.Count – 1

‘ If the answer is Yes, then sort in ascending order.

If iAnswer = vbYes Then

If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then

Sheets(j).Move After:=Sheets(j + 1)

End If

‘ If the answer is No, then sort in descending order.

ElseIf iAnswer = vbNo Then

If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then

Sheets(j).Move After:=Sheets(j + 1)

End If

End If

Next j

Next i

End Sub

Step 3 – Now you can just close the VBA editor and you’re now going to run the Macro from Microsoft Excel. To do that, pres Alt + F8 on your keyboard and this will bring up a list of macros on the Macro dialog box. Just click on the macro that you’ve just created and click on “Run.” It should then sort all of your worksheet tabs in alphabetical order.


ADVERTISEMENTS



Share This on Facebook

Up Next:
Firefox - How to Delete Your Account

Firefox - How to Delete Your Account

The account that you use in the Firefox browser lets you sync all your passwords, bookmarks, as well as other browsing data across devices. In other words, all your data that can be found within the desktop version of the browser can also be used when accessing your account from your smartphone. However, should there come a time when you want to de...Read More


 
Microsoft Excel – How to Sort Worksheets in Alphabetical Order
4 (80%) ratings from 37 users

 

Visitors Interest: