How to alphabetize tabs in Excel

The tutorial shows how you can quickly sort Excel worksheets in alphabetical order by using VBA code and the Workbook Manager tool.

Microsoft Excel provides a number of quick and easy ways to arrange columns or rows in alphabetical order. But there is only one method to rearrange worksheets in Excel - drag them to the desired position on the sheet tab bar. When it comes to alphabetizing tabs in a really large workbook, this may be a long and erroneous way. Looking for a time-saving alternative? There exist only two: VBA code or third-party tools.

How to alphabetize tabs in Excel with VBA

Below you will find three VBA code examples to sort Excel sheets ascending, descending, and in either direction based on the user's choice.

Implying that you have some experience with VBA, we will only outline the basic steps to add a macro to your worksheet:

  1. In your Excel workbook, press Alt + F11 to open the Visual Basic Editor.
  2. On the left pane, right-click ThisWorkbook, and then click Insert > Module.
  3. Paste the VBA code in the Module window.
  4. Press F5 to run the macro.

For the detailed step-by-step instructions, please see How to insert and run VBA code in Excel.

Tip. If you want to keep the macro for further usage, be sure to save your file as an Excel macro-enabled workbook (.xlsm).

Alternatively, you can download our sample Alphabetize Excel Tabs workbook, enable content if prompted, and run the desired macro directly from there. The workbook contains the following macros:

  • TabsAscending - sort sheets alphabetically from A to Z.
  • TabsDescending - arrange sheets in the reverse order, from Z to A.
  • AlphebetizeTabs - sort sheet tabs in both directions, ascending or descending.

With the sample workbook downloaded and open in your Excel, open your own workbook where you want to alphabetize tabs, press Alt + F8, select the desired macro, and click Run.

Sort Excel tabs alphabetically from A to Z

This little macro arranges the sheets in the current workbook in ascending alphanumeric order, first worksheets whose names start with numbers, then sheets from A to Z.

Sub TabsAscending()

For i = 1 To Application.Sheets.Count
	For j = 1 To Application.Sheets.Count - 1
		If UCase$(Application.Sheets(j).Name) > UCase$(Application.Sheets(j + 1).Name) Then
			Sheets(j).Move after:=Sheets(j + 1)
		End If
MsgBox "The tabs have been sorted from A to Z."

End Sub

Arrange Excel tabs from Z to A

If you want to sort your sheets in descending alphanumeric order (Z to A, then sheets with numeric names), then use the following code:

Sub TabsDescending()

For i = 1 To Application.Sheets.Count
	For j = 1 To Application.Sheets.Count - 1
		If UCase$(Application.Sheets(j).Name) < UCase$(Application.Sheets(j + 1).Name) Then
			Application.Sheets(j).Move after:=Application.Sheets(j + 1)
		End If

MsgBox "The tabs have been sorted from Z to A."
End Sub

Alphabetize tabs ascending or descending

This macro lets your users decide how to sort worksheets in a given workbook, alphabetically from A to Z or in the reverse order.

Since the standard dialog box (MsgBox) in Excel VBA only allows choosing from a handful of predefined buttons, we will create our own form (UserForm) with three custom buttons: A to Z, Z to A, and Cancel.

For this, open the Visual Basic Editor, right-click ThisWorkbook, and click Insert > UserForm. Name your form SortOrderFrom, and add 4 controls to it: a label and three buttons:
Create a UserForm to alphabetize Excel tabs ascending or descending.

Next, press F7 (or double-click the form) to open the Code window and paste the below code there. The code intercepts button clicks and assigns a unique tag to each button:

Private Sub CommandButton1_Click()
	Me.Tag = 1
End Sub

Private Sub CommandButton2_Click()
	Me.Tag = 2
End Sub

Private Sub CommandButton3_Click()
	Me.Tag = 0
End Sub

Depending on whether the user clicks the A to Z or Z to A button on your form, sort tabs in ascending alphabetical order (selected by default) or descending alphabetical order; or close the form and do nothing in case of Cancel. This is done with the following VBA code, which you insert in the usual way via Insert > Module.

Sub AlphebetizeTabs()
	Dim SortOrder As Integer

	SortOrder = showUserForm

	If SortOrder = 0 Then Exit Sub

	For x = 1 To Application.Sheets.Count
		For y = 1 To Application.Sheets.Count - 1
			If SortOrder = 1 Then
				If UCase$(Application.Sheets(y).Name) > UCase$(Application.Sheets(y + 1).Name) Then
					Sheets(y).Move after:=Sheets(y + 1)
				End If
			ElseIf SortOrder = 2 Then
				If UCase$(Application.Sheets(y).Name) < UCase$(Application.Sheets(y + 1).Name) Then
					Sheets(y).Move after:=Sheets(y + 1)
				End If
			End If
End Sub

Function showUserForm() As Integer
	showUserForm = 0

	Load SortOrderForm
	SortOrderForm.Show (1)
	showUserForm = SortOrderForm.Tag

	Unload SortOrderForm
End Function

If you are not very comfortable with VBA yet, you can simply download our Sample Workbook to Alphabetize Tabs, open it in your Excel alongside your own file where you want to sort tabs, and run the AlphebetizeTabs macro from your workbook:
Run the macro to sort Excel tabs alphabetically or in the reverse order.

Choose the preferred sort order, say, A to Z, and observe the results:
Choose to arrange the sheet tabs alphabetically from A to Z.

How to sort Excel tabs alphabetically with Ultimate Suite

The users of our Ultimate Suite for Excel don't have to fiddle around with VBA - they have a multi-functional Workbook Manager at their disposal:
Workbook Manager for Excel

With this tool added to your Excel ribbon, alphabetizing tabs is done with a single button click, exactly as it should be!
Alphabetize tabs in Excel with a button click.

If you are curious to explore this and 60+ more professional tools for Excel, a trial version of our Ultimate Suite is available for download here.

I thank you for reading and hope to see you on our blog next week!

You may also be interested in:

6 Responses to "How to alphabetize tabs in Excel"

  1. Kimosabe456 says:

    I created a table with the letter "G" in certain cells (one column).
    I'm trying to get a sum of the number of cells with the letter "G".
    Also needing a sum of the cells with the letter "G" that are green in color.

    I have tried several samples I found at your website; with no success.

    Thank you.

    • Doug says:

      Here's how to count the cells that contain "G":
      =COUNTIF(A3:A35,"G") where the G cells are in the range A3 to A35.
      To count the formatted cells you'll need to look at the above discussion and get the VBA solution.

  2. krishnadevan says:

    i want to copy the headi of main sheet that sheet 01. and paste that heading multyple sheets with numarical order
    eg: heading work id 1053(sheet 01) copy this heading and paste this heading in every pages. but the sheet name is renamed automaticaly that sheet 02,sheet 03 sheet 04 etc in every sheets automaticaly..pls help me

  3. Nick Simpson says:

    Thank you so much, saved me so much time!!

  4. Lucas Mepham says:

    Great information there! Is it at all possible to organise sheets in descending date order? Any help would be appreciated.


  5. Jaime says:

    Oh my gosh, this is great! Thank you so much! So easy!

Post a comment

Unfortunately, due to the volume of comments received we cannot guarantee that we will be able to give you a timely response. When posting a question, please be very clear and concise. We thank you for understanding!
Ultimate Suite 2018.5 for Excel
60+ professional tools for Excel 2019-2007 to do your daily work
Incredible product, even better tech support…AbleBits totally delivers!
Deborah Bryant
Anyone who works with Excel is sure to find their work made easier
Jackie Lee
The best spent money on software I've ever spent!
Patrick Raugh
Ablebits is a fantastic product - easy to use and so efficient.
Debra Celmer
Excel is at its best now
Annie C.
I don't know how to thank you enough for your Excel add-ins
Jennifer Morningstar
Anybody who experiences it, is bound to love it!
Kumar Nepa
AbleBits suite has really helped me when I was in a crunch!
Nelda Fink
I have enjoyed every bit of it and time am using it
Christian Onyekachi Nwosu
It's the best $100 we've ever spent!
Mike Cavanagh
I love the program, and I can't imagine using Excel without it!
Robert Madsen
One word… WOW!
Dave Brown
Love the products!
David Johnston
It is like having an expert at my shoulder helping me…
Linda Shakespeare
Your software really helps make my job easier
Jeannie C.
Thanks for a terrific product that is worth every single cent!
Dianne Young
I love your product
Brad Gibson
Sheila Blanchard