How to Sort by Last Name in Excel (4 Quick Approaches)

While working with name-based Excel datasheets, sorting the data depending on the names is one of the most common processes. But usually, this sorting is done based on the first name basis. However, it is not possible to alphabetize the datasets using the last names in the same way. We will need to extract the last name from the full name list first and insert it in a separate column. Once that is done, we can easily sort by the last name in Excel in just a few steps.  

Key Takeaways

Extract the last name into a new column from the full name by using a specific method. For instance, you can use Flashfill to do this.
Name the new column as “Last Name”.
Go to the Data tab from the ribbons and select Sort.
Choose Sort By > Last Name and press OK. 

overview image - sort by last name

This article covers four different methods of sorting the dataset in alphabetical order using the last names. Utilizing Find and Replace, Text to Columns, Formulas and Flashfill are the ways discussed in this article along with proper directions.  

Download Practice Workbook
1

Sort by Last Name using Find and Replace

The first and foremost step will be to create a separate column containing only the last names of the existing dataset of full names. We are going to use the Find and Replace method in order to complete this action. Suppose you have the following dataset that you want to sort by last name:  

dataset for Sort by Last Name using Find and Replace

 

Steps: 
Select the dataset column including the header. In this sheet, it will be from A1 to A13. 

selecting the cells

Copy the names.
Create a new column just beside column A by clicking on Column B header and pressing on Insert.  

clicking insert option

A new column will be created. Right click on column B now and click on paste. The full name list from column A will now be copied to column B. 

clicking paste option

Rename the copied column as “Last Name”. 

renaming the column

Now, select all the copied names from column B without the header.
Press and hold the  Ctrl  +  H  key at the same time to open a Find and Replace dialogue box. 

Opening Find and replace dialogue box

In the Find box, put an asterisk (*) sign and then press on the space bar. Keep the Replace box completely empty. This is to remove everything before the last name, including the first names and the spaces after the first name in column B. 

putting asterisk sign

Now, click on Replace All to automatically replace all the names in column B with only last names.  

replacing with last names

Select all the columns in the sheet.   

selecting all the columns in the sheet

On the tabs, go to Data and select Sort. A sorting box will now pop up.  

sorting box

In this box, go to the drop down button beside Sort by and choose Last Name 

choosing sort by and last name option

Beside the order drop down box, select A to Z or Z to A according to your preference of sorting by ascending or descending order respectively. 

selecting order

Click on OK. Now the entire dataset will be sorted by the last names of the list of column A. You can now Delete column B if you don’t want only the last names to be showing in the sheet.  

sorted dataset

This method is the best option to sort by last name as it will work even if there are middle names in the full names. As long as the last name is the last word in each cell, this method will be the perfect and simplest to complete the action.  


2

Sort by Last Name Using Text to Columns

This method will only work when all the cells either have first and last names or first, middle and last name. If some cells include first, middle and last names and the other cells don’t, then this method will not work correctly. In order to use this method in case of our sample datasheet, follow the steps below.  

Steps: 

First, create a new empty column just beside column A by clicking on the Column B header and pressing on Insert. 
Select the names in column A.  

selecting column A

Go to the Data tab in the ribbons and click on Text to Columns option. This will open the Text to Column wizard box which has 3 steps.
Choose the File Type as Delimited and press Next. 

choosing file type as delimitted

In the next step, you will need to select the Delimiter where you will tick on the Space box. Then go to the Next step. 

ticking on the space box

In Step 3, select the Do not Import Column option under the Column Data Format section. You can see in the Data preview section the selected first names that we will remove. 
Now, in the same step, in the Destination box currently it will show $A$2, but take the cursor to the B2 cell and click on it. The destination box will change to $B$2 now, which is our targeted column B.  

clicking don't import column

Click Finish and column B will now show all the last names of the column A full names. 

column A full names

Select all the columns in the sheet.   

selecting whole sheet

On the tabs, go to Data and select Sort. A sorting box will now pop up.  

opening sorting box

In this box, go to the drop-down button beside Sort by and choose Last Name.  

clicking sort by and last name option

Beside the order drop down box, select A to Z or Z to A according to your preference of sorting by ascending or descending order respectively. 

sorting A to Z or Z to A

Click on OK. Now the entire dataset will be sorted by the last names of the list of column A. You can now Delete column B if you don’t want only the last names to be showing in the sheet.  

sorted dataset


3

Sort by Last Name using Formula

This method is the most dynamic one as after establishing the formula, we could insert more names in column A, and the formula will automatically extract their last names into a separate column. We don’t have this privilege with the first two methods as the names need to be pre-existing in those cases. 

Type 1: Data With No Middle Names  

In this type of data, only first and last names are present in all cells. No middle name is in the dataset so we will be using the previous data and follow the steps below: 

Steps: 

First, create a new empty column just beside column A by clicking on Column B header and pressing on Insert. 
Type in cell B2 the necessary formula

=RIGHT(A2,LEN(A2)-FIND(” “,A2))
 and press Enter. Make sure to put a space between the “ “ of the FIND function because we extract the names after space in each column. 

writing formula

Now select the B2 cell and pull it down all the way to the B13 cell to apply the formula to the whole column.  

dragging down data

All the cells of column B will now have only the last names.  

last names of all columns

Select all the columns in the sheet.   

selecting all columns

On the tabs, go to Data and select Sort. A sorting box will now pop up.  

sorting dialogue box

In this box, go to the drop down button beside Sort by and choose Last Name.  

selecting sort by and last names option

Beside the order drop down box, select A to Z or Z to A according to your preference of sorting by ascending or descending order respectively. 

sorting A to Z

Click on OK. Now the entire dataset will be sorted by the last names of the list of column A. You can now Delete column B if you don’t want only the last names to be showing in the sheet.  

Type 2: Data with Middle Names 

When the names include their middle names, we will need to use a different formula. We have taken some data this time which have middle names in their full names.  

Steps: 

First, create a new empty column just beside column A by clicking on Column B header and pressing on Insert.  

created last name column

Type in cell B2 the necessary formula 

=RIGHT(A2,LEN(A2)-FIND(“@”,SUBSTITUTE(A2,” “,”@”,LEN(A2)-LEN(SUBSTITUTE(A2,” “,””)))))  
 

➤ And press Enter.
Now select the B2 cell and pull it down all the way to the B13 cell to apply the formula to the whole column. The last names will be extracted in column B.  

pulling down the formula

Select all the columns in the sheet.
On the tabs, go to Data and select Sort. A sorting box will now pop up.
In this box, go to the drop-down button beside Sort by and choose Last Name.
Beside the order drop down box, select A to Z or Z to A according to your preference of sorting by ascending or descending order respectively. 

A to Z sorting

Click on OK. Now the entire dataset will be sorted by the last names of the list of column A. You can now delete column B if you don’t want only the last names to be showing in the sheet.  

Sorted Dataset


4

Sort by Last Names Using Flash Fill

This method, by far, is the simplest method to sort last names on excel. However, older versions of Excel 2010 and earlier do not have the Flash fill feature in it. So, this is not applicable to all Excel users. If you are using an Excel version older than 2010, you can easily sort the last names using the following steps.  

Steps: 

Create a new empty column just beside column A by clicking on Column B header and pressing on Insert.
For the first name in A2, go to the adjacent cell B2 and type the last name. For instance, in this sheet, type Davis in the B2 cell.
Similarly, for cell A3, type in Thompson in the B2 cell. 

typing last name in cell A2 and A3

Now, select both of these cells.
Hover the cursor at the corner of the cell and drag and select all the cells in column B.
There will be an Autofill box at the corner of the last cell. Click on it and select the Flash fill option. 

clicking flash fill option

Now, all the adjacent cells will be filled up with the respective last names.  

adjacent cells filled up

Select all the columns in the sheet.
On the tabs, go to Data and select Sort. A sorting box will now pop up.
In this box, go to the drop-down button beside Sort by and choose Last Name.
Beside the order drop down box, select A to Z or Z to A according to your preference of sorting by ascending or descending order respectively.
Click on OK. Now the entire dataset will be sorted by the last names of the list of column A. 

clicking sorting option


FAQ 

Can I Sort by the Last Names Without Splitting the Columns? 

No, it is not possible in Excel to sort your full names and data without splitting the last names into different columns. You will need to choose any method to extract the last name temporarily and sort according to it. Afterwards, you can delete the column containing last names if you don’t want it there anymore. It won’t change the sorting. 

How can I Sort the List by Last Name and Then First Name? 

You need to split the full names into two different columns and name them “Last Name” and “First Name” accordingly. After that, select the whole dataset, go to Data>Sort. From the Add Level option, add two Sort Levels here and choose Sort By>Last Name at the first level, then choose Sort by>First Name at the second level.  

How To Sort by Last Name When the Name Includes a Middle Name? 

In case of full names containing a middle name as well, the best way to sort by last name is to use a specific formula. This formula only targets and extracts the very last word from the cell which will be the last name. Use the formula:
=RIGHT(A2,LEN(A2)-FIND(“@”,SUBSTITUTE(A2,” “,”@”,LEN(A2)-LEN(SUBSTITUTE(A2,” “,””)))))
Here, A2 cell needs to hold the first name of the list.   

Will Excel Automatically Update the Sorting by Last Name if I Enter a New Full Name? 

No, if you have used Flash fill, Text to Columns or Find and Replace method to sort by the last name, Excel won’t update the sorting of the new entries. You will need to redo the sorting method once again for the sorting condition to apply to the new data. However, if you have used a formula for sorting by last name, it will automatically update the sorting by last name within the selected cells the formula is applied to.  


Wrapping Up 

In this article, we have covered four different methods of how to sort by last names in Excel. In all cases, the last names need to be in a separate column in order to sort them alphabetically. For this, we have explored the Find and Replace, Text to Column, Flash fill options as well as using specific formulas for the action.

Hope this article was helpful for you to sort your data by the last names. Feel free to leave a comment and suggestion.  

ExcelInsider Team
We will be happy to hear your thoughts

Leave a reply

Excel Insider
Logo