search
HomeTopicsexcelHow to alphabetize tabs in Excel in ascending and descending order

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 Code 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.
  • AlphabetizeTabs - 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 Next Next 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) Then Application.Sheets(j).Move after:=Application.Sheets(j 1) End If Next Next 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:

How to alphabetize tabs in Excel in ascending and descending order

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 Me.Hide End Sub Private Sub CommandButton2_Click() Me.Tag = 2 Me.Hide End Sub Private Sub CommandButton3_Click() Me.Tag = 0 Me.Hide 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 AlphabetizeTabs() 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) Then Sheets(y).Move after:=Sheets(y 1) End If End If Next Next 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 AlphabetizeTabs macro from your workbook:

How to alphabetize tabs in Excel in ascending and descending order

Choose the preferred sort order, say, A to Z, and observe the results:

How to alphabetize tabs in Excel in ascending and descending order

Tip. With VBA, you can also create copies of your Excel worksheets. The code is available here: How to duplicate sheet in Excel with VBA.

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:

How to alphabetize tabs in Excel in ascending and descending order

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

How to alphabetize tabs in Excel in ascending and descending order

If you are curious to explore this and 70 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!

The above is the detailed content of How to alphabetize tabs in Excel in ascending and descending order. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MEDIAN formula in Excel - practical examplesMEDIAN formula in Excel - practical examplesApr 11, 2025 pm 12:08 PM

This tutorial explains how to calculate the median of numerical data in Excel using the MEDIAN function. The median, a key measure of central tendency, identifies the middle value in a dataset, offering a more robust representation of central tenden

Google Spreadsheet COUNTIF function with formula examplesGoogle Spreadsheet COUNTIF function with formula examplesApr 11, 2025 pm 12:03 PM

Master Google Sheets COUNTIF: A Comprehensive Guide This guide explores the versatile COUNTIF function in Google Sheets, demonstrating its applications beyond simple cell counting. We'll cover various scenarios, from exact and partial matches to han

Excel shared workbook: How to share Excel file for multiple usersExcel shared workbook: How to share Excel file for multiple usersApr 11, 2025 am 11:58 AM

This tutorial provides a comprehensive guide to sharing Excel workbooks, covering various methods, access control, and conflict resolution. Modern Excel versions (2010, 2013, 2016, and later) simplify collaborative editing, eliminating the need to m

How to convert Excel to JPG - save .xls or .xlsx as image fileHow to convert Excel to JPG - save .xls or .xlsx as image fileApr 11, 2025 am 11:31 AM

This tutorial explores various methods for converting .xls files to .jpg images, encompassing both built-in Windows tools and free online converters. Need to create a presentation, share spreadsheet data securely, or design a document? Converting yo

Excel names and named ranges: how to define and use in formulasExcel names and named ranges: how to define and use in formulasApr 11, 2025 am 11:13 AM

This tutorial clarifies the function of Excel names and demonstrates how to define names for cells, ranges, constants, or formulas. It also covers editing, filtering, and deleting defined names. Excel names, while incredibly useful, are often overlo

Standard deviation Excel: functions and formula examplesStandard deviation Excel: functions and formula examplesApr 11, 2025 am 11:01 AM

This tutorial clarifies the distinction between standard deviation and standard error of the mean, guiding you on the optimal Excel functions for standard deviation calculations. In descriptive statistics, the mean and standard deviation are intrinsi

Square root in Excel: SQRT function and other waysSquare root in Excel: SQRT function and other waysApr 11, 2025 am 10:34 AM

This Excel tutorial demonstrates how to calculate square roots and nth roots. Finding the square root is a common mathematical operation, and Excel offers several methods. Methods for Calculating Square Roots in Excel: Using the SQRT Function: The

Google Sheets basics: Learn how to work with Google SpreadsheetsGoogle Sheets basics: Learn how to work with Google SpreadsheetsApr 11, 2025 am 10:23 AM

Unlock the Power of Google Sheets: A Beginner's Guide This tutorial introduces the fundamentals of Google Sheets, a powerful and versatile alternative to MS Excel. Learn how to effortlessly manage spreadsheets, leverage key features, and collaborate

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools