Others

How to Fix Excel Sort Not Arranging Last Names Alphabetically

Khadija KhanKhadija Khan Oct 12, 2026 871 views

Question details

The user needs to sort a dataset by Date and then by Last Name, but the spreadsheet fails to alphabetize the last names correctly.

How to Fix Excel Sort Not Arranging Last Names Alphabetically
Product
Microsoft Excel
Device & OS
not provided
Scenario
Organizing data using multiple sort levels, specifically sorting by Date first, followed by Last Name and First Name.
Observed behavior
Dates are sorted correctly in the first level, but last names and first names in the subsequent levels do not follow the expected alphabetical order.
Before you start

Before troubleshooting the sorting issue, ensure your dataset has clear column headers and no merged cells within the data range, as these can disrupt the sorting process.

Solution 1Recommended

Clean Hidden Spaces and Apply Custom Sort

Hidden spaces or non-printable characters often break alphabetical sorting. Cleaning the text ensures accurate multi-level sorting.

Excel evaluates space characters before letters. If some names have leading spaces, they will not sort properly alongside names without spaces. Using the TRIM and CLEAN functions will normalize the text.

1
Create a helper column

Insert a new column next to your 'Last Name' column. In the first empty cell of the new column, type the formula =TRIM(CLEAN(B2)) (assuming B2 contains the first last name) and press Enter.

2
Copy the cleaned data

Drag the fill handle down to apply the formula to all rows. Select the newly generated names, copy them, right-click the original 'Last Name' column, and select 'Paste as Values' to replace the messy data.

3
Open Custom Sort

Select your entire data range. Go to the Data tab on the ribbon and click 'Sort' to open the Custom Sort dialog box.

4
Configure sort levels

Add Level 1: Sort by 'Date' (Oldest to Newest). Click 'Add Level'. Add Level 2: Sort by 'Last Name' (A to Z). Click OK to apply the sort.

Clean Hidden Spaces and Apply Custom Sort
Data Range Headers: Always ensure the 'My data has headers' box is checked in the upper right corner of the Sort dialog box so your column titles aren't mixed into the sorted data.
Efficient Sorting in WPS Spreadsheet

Easily Sort Complex Data with WPS Office

WPS Spreadsheet offers an intuitive custom sort feature, allowing you to seamlessly organize multiple levels of data, clean up text strings, and manage large datasets with perfect Microsoft Excel compatibility.

  1. 1. Open your workbook: Launch WPS Spreadsheet and open the file containing your data.
  2. 2. Select Data and Sort: Highlight your data range, navigate to the Data tab, and click the 'Sort' icon to access the Custom Sort dialog.
  3. 3. Add Sorting Levels: Set the primary condition (e.g., Date), then click 'Add Level' to specify your secondary condition (e.g., Last Name).
  4. 4. Apply settings: Verify 'My data has headers' is checked, and click OK to perfectly alphabetize your records.
Easily add multiple sorting levels like Date, Last Name, and First Name.Fully compatible with Microsoft Excel (.xlsx, .xls, .csv) files and formats.Built-in text functions (TRIM, CLEAN) to prepare your data effortlessly.Free, lightweight, and user-friendly interface.
QA img-9

Frequently Asked Questions

Why does Excel sort some names correctly but ignore others?

This usually happens because of hidden leading spaces before the names. Excel evaluates space characters before alphabetical letters, pushing those names to the top or bottom of the list. Using the TRIM function removes these hidden spaces.

How do I sort by last name if the full name is in one column?

You must first separate the names. Use the Text to Columns feature under the Data tab, or use Flash Fill to extract the last names into a new column, then sort by that new column.

Why is the Custom Sort option greyed out?

Custom Sort may be disabled if your worksheet is protected, if multiple sheets are grouped, or if you are trying to sort a shared workbook with restricted permissions. Go to the Review tab and click 'Unprotect Sheet' to restore functionality.