Open In App

How to Sort by the Last Name in Excel?

Last Updated : 03 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

When you work on excel you’ll probably be assigned a task to sort data alphabetically in ascending or descending order and it is quite an easy task to sort data using the first names in either of the order. It is the easiest task to be done in excel. But what if you are given a task to sort a list of names according to their last name in ascending or descending order. Quiet confusing, right?. This article will help you to understand the ways in which you can sort data according to the last name from the data set given to you in three ways by using built-in Microsoft Excel functions.

Sort Using Flash Fill

Flash Fill is an addition to Microsoft Excel 2013 that will automatically fill your data when it senses a pattern. For example, Flash Fill can separate first and last names from a single column or combine first and last names from two different columns.

Note: Flash Fill feature is added in MS Excel 2013 and it will be available in 2013 and later versions of excel.

For Example:

Names-Example

 

Step 1:  Write the last name from the names given in the list to

Separated-last-names

 

cell D1. Write at least 2 last names into column D. (as shown below). 

Step 2: Select both cells and hover the cursor over the bottom-right part of the selection(as shown in a circle below). You will notice that the cursor changes to a plus icon.

Select-both-cells

 

Step 3: Drag the plus icon to the last entry of your data. You’ll notice an AutoFill Option (Marked in a circle below, Fig.1 ). Click on the AutoFill option, and a drop-down menu will appear in which you have to select Flash Fill (Fig. 2). 

Drag-the-plus-sign

Fig. 1

Auto-Fill-option

Fig. 2

You’ll see all the last names are now in column D.

Step 4: Select the entire dataset and click on Data Tab> Sort & Filter > Sort (as shown below).

Data-Tab-Sort-&-Filter-Sort

 

Step 5:  A dialogue box will appear(as shown below). In the Sort by option add the column name, here column name to be sorted is D. In the Order option, select the order in which you want to sort your data, and in Sort On option select values because we have text as values in the cell. Click OK

Sort-Dialogue-Box

 

Output: The data will be sorted alphabetically according to last names. Delete the last names written in Column D and you’ll get the desired output.

Output

 

Sort Using Find and Replace

As the name suggests, Find and Replace is a functionality that helps us to find a value or number in the sheet and replace it with the desired number or value. It is used when we have mistakenly typed the wrong spelling everywhere in the sheet and need to correct it. It will take a lot of time to find the wrong spelling one by one and then replace it. The example would be taken as above.

Step 1: Copy the data that needs to be sorted into the adjacent column. (as shown below)

Copied-dataset

 

Step 2: Select the copied data, in our example select the data from column D and press Ctrl+F to open the find and replace dialogue box (as shown below). 

Find-and-Replace-Dialogue-box

 

Step 3: In the dialogue box open the Replace option and put an asterisk (*) followed by a single space in Find what field. Leave the Replace with empty. And press Replace All (as shown above). The output will only have last names in the D column.

Note: The above steps work well even when you have middle names or prefixes (such as Mr. or Ms) in your data. It will only return last names.

Find-and-Replace-output

 

Step 4: Select the entire dataset and click on Data Tab> Sort & Filter > Sort (as shown below).

Data-Tab-Sort-&-Filter-Sort

 

Step 5:  A dialogue box will appear(as shown below). In the Sort by option add the column name, here column name to be sorted is D. In the Order option, select the order in which you want to sort your data, and in Sort On option select values because we have text as values in the cell. Click OK

Sort-Dialogue-Box

 

Output: The data will be sorted alphabetically according to last names. Delete the last names written in Column D and you’ll get the desired output.

Output

 

Sort Using Text to Columns

Text to Columns is a function provided by MS Excel that helps you to split text written in one cell into multiple cells. The example would be the same.

Step 1: Select the data and go to Data Tab>Sort & Filter> Text to Columns

Text-to-columns

 

Step 2: A dialogue box will appear(as shown below). Select Delimited and press Next> button.

Convert-Text-to-Column

 

Step 3: Click on Space, if your delimiter is a comma or semicolon instead of space click on that. Now click Next> (as shown below).

Convert-Text-to-Column

 

Step 4: Select General in Column data format and add the cell value adjacent to the original data in Destination and click Finish.

Convert-Text-to-Column

 

The output will look like this.

Text-to-columns

 

Now repeat steps 4 and 5 from Sort using Flash Fill and you’ll be done. But remember now your data through which you want to sort is in Column E.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads