Excel exists to bring order to the chaos of information in your spreadsheets. One of the many ways that Excel can do that is by sorting data. Scanning through data that has some sort of order is much easier, and when it comes to names and words, a popular method is to sort them alphabetically.

You can use the Sort tool to easily sort your data alphabetically in Excel. Alternatively, you can create a VBA Macro for this purpose and assign a hotkey to sort data faster.

Sorting Alphabetically in Excel With the Sort Tool

Excel has a built-in tool called Sort that lets you sort your data. The Sort tool is capable of sorting data on various scales, and it also allows you to sort data alphabetically with a couple of clicks.

Sample spreadsheet in Excel

In this sample spreadsheet, we've got the names of some contractors and how much they've earned. The goal is to sort this table by name using the Sort tool in Excel.

  1. Select the entire data table. In this example, that will be cells A2 to B11.
  2. Go to the Data tab from the Excel Ribbon.
  3. In the Sort & Filter section, click on Sort. This will open the Sort window.
    Excel Sort window
  4. In the Sort window, under Column, select the column that you want to sort the table by. That will be the Name column in this example.
  5. Under Sort On, select Cell Values.
  6. Under Order, select A to Z. You can also set this to Z to A to sort data in descending order.
  7. Select OK.

Excel will now sort your data table by the column you selected, on cell values, and in ascending order.

Sorting Alphabetically in Excel With VBA

Using VBA to sort data alphabetically in Excel can be a bit more complicated the first time, but this effort rewards you with effortlessly sorting data alphabetically later on. If you're unfamiliar with VBA, we suggest that you read our Excel VBA beginner's guide to get a head start.

Sample spreadsheet in Excel

Let's try and sort the data in another sample spreadsheet in Excel using VBA code. This spreadsheet includes a single column.

  1. Go to the Developer tab from the Excel Ribbon.
  2. In the Code section, select Macros. This will open the Macro window.
    Excel Macro window
  3. Enter a name for your macro under Macro name.
  4. Click on Create. This will take you to the VBA code editor.
    Blank macro in Excel
  5. In the code editor, enter the code below:
            Sub AZSort()

    Dim R As Range
    ActiveSheet.Sort.SortFields.Clear
    Set R = Selection.Columns(1)
    R.Select

    R.Sort Key1:=R.Cells(1), Order1:=xlAscending, Header:=xlNo


    End Sub
Sort macro VBA code in Excel

Before we proceed, let's break down this code. The first and last lines are automatically created by VBA and mark the start and finish of the macro. We named the macro AZSort in this example. If you've used a different name, then that name will appear instead of AZSort.

The next line defines the variable R as a Range. You can change R to any other name you want; just remember to stay consistent throughout the code, as this variable is addressed a bunch of times in the code.

Next, we refer to the current sheet, and then clear all previous sorting so that our new sorting can take its place. Then, we set the variable R to equal the first column of selected cells. R.Select simply selects the variable R.

Finally, the R.Sort line sorts the column. The Header parameter indicates whether the selection includes a header or not. You can read about how Cells and Range differ in Excel VBA in our in-depth article. Now that you have an adequate understanding of the Macro you just wrote, let's use it on the column.

  1. Go back to the Macro window.
  2. Select your macro and then click on Options.
  3. Set a shortcut key for the macro.
    Excel macro options
  4. Press OK.
  5. Select the column that you want to sort.
  6. Press the keyboard shortcut for your macro on your keyboard.

There you have it! Although setting up the macro might take a bit more time, but from now on, all you need to do is to select the cells and press a keyboard shortcut, and Excel will sort your cells alphabetically.

Bring Order to Your Excel Spreadsheets

One of Excel's key functions is to organize data to make them more comprehensible. One popular method of sorting names is sorting them alphabetically.

You can either use the Excel Sort tool or write a VBA code to sort alphabetically in Excel. Now that you know how to do both, it's time to bring order to your spreadsheets!