top of page

Excel Macro to Sort Worksheets in Alphabetical Order


Microsoft was some VBA code posted to its support site here:

. .. which will allow you to sort the worksheets of an Excel spreadsheet in alphabetical order. If you have an Excel workbook like this:

. . . enter Visual Basic by pressing ALT + F11, and then put this code in a new module:

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

After you press play, the macro will prompt you to either sort the worksheets in ascending or descending order.

Click yes or no, to get the needed results:


Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page