Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Sort by Surname: How to Organize Name Lists

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To sort by surname in Excel, the method depends on whether the surname is in its own column or combined with the first name in a single cell. If the surname is in its own column, simply select that column and use the Sort & Filter button on the Home tab to sort A-Z. If the names are combined (e.g., "John Smith"), you must first split the names into two columns using the Text to Columns feature before sorting. This ensures that Excel organizes the list by the last name rather than the first name.

What You'll Need

  • A computer with Microsoft Excel installed (works on Windows and macOS).
  • A dataset containing names that you wish to organize.
  • A backup copy of your data (recommended before performing "Text to Columns" operations).

Step-by-Step

Scenario 1: Surnames are already in a separate column

This is the most straightforward method. Use this if your spreadsheet is already organized with "First Name" in Column A and "Last Name" in Column B.

  1. Click any single cell within the column that contains the surnames. Do not highlight the entire column, as this can sometimes lead to Excel asking if you want to "expand the selection," which can be confusing for beginners.
  2. Navigate to the Home tab on the top ribbon.
  3. Look toward the right side of the ribbon for the Editing group and click the Sort & Filter button.
  4. Select Sort A to Z (Ascending) to organize surnames alphabetically from A to Z, or Sort Z to A (Descending) for the reverse.
  5. If a Sort Warning dialog box appears asking if you want to "Expand the selection," always choose Expand the selection and click Sort. This ensures that the first names and any other associated data (like email addresses or phone numbers) move with the surname, keeping the rows intact.

Scenario 2: Names are combined in one cell (e.g., "Jane Doe")

Excel cannot natively "see" the surname if it follows a first name in the same cell. You must isolate the surname first. Note that menu labels may differ slightly depending on your version of Excel or region.

  1. Insert a Blank Column: Right-click the column letter to the right of your name list and select Insert. This provides a destination for the surnames so you don't overwrite existing data.
  2. Select the Data: Highlight the cells containing the full names.
  3. Open Text to Columns: Go to the Data tab on the ribbon and click Text to Columns.
  4. Choose Delimited: In the Convert Text to Columns Wizard, select Delimited and click Next.
  5. Set the Delimiter: Uncheck all boxes except for Space. You will see a preview at the bottom showing the names split into two columns. Click Next.
  6. Set Destination: In the Destination box, instead of the default cell (which would overwrite your original names), click the arrow and select the first cell of the blank column you created in Step 1. Click Finish.
  7. Sort the New Column: Now that the surnames are in their own column, follow the steps in Scenario 1: click a cell in the surname column, go to Home > Sort & Filter > Sort A to Z.

Scenario 3: Using a Custom Sort for Multiple Criteria

If you have multiple people with the same surname (e.g., several people named "Smith"), you will want to sort by surname first, and then by first name.

  1. Highlight your entire data table, including the headers.
  2. Go to the Data tab and click the large Sort button.
  3. In the Sort dialog box, ensure the My data has headers checkbox is checked in the top right corner.
  4. Under Column, select Last Name (or the column containing surnames). Set Sort On to Cell Values and Order to A to Z.
  5. Click the Add Level button at the top of the dialog box.
  6. In the new row ("Then by"), select First Name from the dropdown. Set the order to A to Z.
  7. Click OK. Your list is now perfectly alphabetized by surname, with first names acting as the tie-breaker.

Common Mistakes

  • Sorting only one column: The biggest mistake users make is highlighting only the surname column and clicking sort. If you ignore the "Expand Selection" warning, Excel will sort the surnames but leave the first names where they were. This permanently mismatches your data, assigning the wrong first name to the wrong last name.
  • Ignoring leading spaces: Sometimes data imported from other software contains a hidden space before the name (e.g., " Smith" instead of "Smith"). Excel treats a space as a character that comes before "A," meaning those names will jump to the top of your list regardless of the letter.
  • Overwriting data during split: When using Text to Columns, failing to change the Destination cell will overwrite the original full-name column. While this is sometimes desired, it removes the original record of how the name was written.
  • Assuming "Text to Columns" works for all names: This tool assumes a single space separates names. It fails for names like "Maria van der Berg" or "Jean-Luc Picard," where the surname consists of multiple words or hyphens.

Tips

  • Use Tables: Convert your data range into an official Excel Table (select data and press Ctrl + T). Tables automatically include filter arrows in the header row, allowing you to sort any column with a single click without worrying about "expanding the selection."
  • The TRIM Function: To fix the "leading space" issue mentioned in Common Mistakes, use the formula =TRIM(A2) in a helper column. This removes all unnecessary spaces from the beginning and end of the text. Sort the trimmed column for perfect results.
  • Flash Fill: In newer versions of Excel, you can use Flash Fill instead of Text to Columns. Type the first two surnames from your list into the adjacent blank column. Excel will likely recognize the pattern and suggest a greyed-out list of the remaining surnames. Press Enter to accept them all instantly.
  • Freeze Panes: When sorting large lists, go to View > Freeze Panes > Freeze Top Row. This keeps your "First Name" and "Last Name" headers visible as you scroll through your newly sorted list.

Troubleshooting

If your list is not sorting correctly, try these steps in order:

  1. Check for Hidden Characters: If "Brown" is appearing after "Zuckerberg," check for a leading space. Use the =LEN() function to see if the character count is higher than it looks.
  2. Verify Data Type: Ensure the column is formatted as "General" or "Text." If Excel thinks the data is a different format, sorting may behave unexpectedly.
  3. Clear Existing Filters: If you have an active filter on another column, the sort may only apply to the visible rows. Go to Data > Clear (next to the Filter button) to reset the view.
  4. Undo Mismatched Data: If you accidentally sorted only one column and mismatched your names, press Ctrl + Z immediately to undo. If you have already saved and closed the file, you will need to restore a backup or manually re-align the data.

Frequently Asked Questions

Can I sort by surname if the names are written as "Surname, First Name"?

Yes. If the surname comes first and is separated by a comma, you can sort the column A-Z immediately without splitting the cells, as the surname is already the primary character in the cell.

How do I handle surnames with prefixes like "De" or "Von"?

Excel sorts strictly by the first character. "De Luca" will be sorted under "D." If you need these sorted by the main part of the name, you must manually move the prefix to a separate column or edit the entries.

Does sorting a column affect my formulas?

If your formulas use cell references (like =B2*C2), they will generally update correctly as the rows move. However, if you are referencing a specific cell outside the sorted range, the result may change.

Can I sort by surname and date at the same time?

Yes, using the Custom Sort method. Add the surname as the first level and the date as the second level in the Sort dialog box.

Why is my sort not updating when I add new names?

Sorting is a one-time action, not a live rule. When you add new data to the bottom of the list, you must perform the sort process again to integrate the new entries into the alphabetical order.