Sorting by last name in Excel is the process of rearranging rows based on the last names extracted from full names stored in a single column.
How to sort by last name in Excel
To sort by last name in Excel, extract the last name into a helper column and apply a standard sort.
Windows and Mac steps
Windows and Mac follow the same steps for this task. The interface layout remains identical for this feature.
Step-by-step instructions
-
Enter full names in one column, for example Column A.
-
Create a helper column in Column B.
-
Enter the formula that extracts the last name:
=TRIM(RIGHT(A2, LEN(A2) - FIND("@", SUBSTITUTE(A2, " ", "@", LEN(A2) - LEN(SUBSTITUTE(A2, " ", ""))))))
-
Press Enter and fill down the column.
-
Select the range covering both the full names and extracted last names.
-
Open the Data tab.
-
Click Sort.
-
Select Column B as the “Sort by” option.
-
Set Sort On to “Values”.
-
Set Order to A to Z.
-
Click OK.
Why does this method work?
The helper column isolates everything after the last space, which forms the last name. Excel uses this value as the basis for sorting. Name structures with one, two, or multiple words work with this approach because the function identifies the last segment consistently.
How to handle names with suffixes
Suffixes such as Jr., Sr., III, or PhD appear at the end of a name and shift the sorting order. The sort remains accurate when suffixes are removed before sorting. A preprocessing column with CLEAN or SUBSTITUTE can remove suffixes before extraction.
How to sort by last name without a helper column
Excel provides Flash Fill, which creates the last name column automatically.
Steps:
-
Enter the first last name manually next to the top cell.
-
Press Ctrl + E.
-
Excel fills down extracted last names.
-
Sort using the filled column.
Flash Fill uses pattern recognition with 92% accuracy for typical name structures. The error rate increases with multi-part surname structures.
How to sort by last name when names are “First Middle Last.”
The helper formula still identifies the last element. The extraction logic measures the distance from the final space to the end of the string.
How to sort by last name when names contain hyphens
Hyphenated last names sort alphabetically, starting from the first character of the hyphenated segment. Excel treats hyphens as characters in the sort order, which maintains consistent ordering across the list.