Are you working with a large Excel dataset and need to sort it by last name while keeping rows together? You're in the right place. In this guide, we'll walk yo...
Are you working with a large Excel dataset and need to sort it by last name while keeping rows together? You're in the right place. In this guide, we'll walk you through a simple yet powerful method to achieve this, ensuring your data remains organized and easy to navigate.

Before we dive in, let's assume you have a dataset similar to this:

| First Name | Last Name |
|---|---|
| John | Doe |
| Jane | Smith |
| Michael | Johnson |
| Emily | Davis |
Now, let's sort this by last name while keeping rows together.
![[EP 6] Excel Tips Separate First and Last name](https://i.pinimg.com/originals/87/eb/6d/87eb6d654567dd470adbeebc15ff6f64.png)
Excel's Flash Fill feature can help you sort data by last name efficiently. Here's how to use it:

1. **Select your data**: Click on the cell with the first name, then drag your cursor to select all the first name cells.
2. **Flash Fill suggestion**: After selecting, you'll see a small lightbulb icon appear in the bottom-right corner of the selected cells. Click on it.

3. **Accept the suggestion**: In the dropdown menu, click on 'Flash Fill'. Excel will automatically suggest a column for last names. If it's correct, click 'OK'.
4. **Sort by last name**: With your last name column selected, click on the 'Sort & Filter' button in the 'Home' tab. Then, choose 'Sort A to Z' or 'Sort Z to A' depending on your preference.

5. **Keep rows together**: After sorting, your data will be sorted by last name, but rows might not be together. To fix this, select the entire dataset, go to the 'Data' tab, and click on 'Remove Duplicates'. In the dialog box, uncheck 'My data has headers' if your data doesn't have headers, then click 'OK'.




















If Flash Fill didn't work as expected, you can use Power Query, a powerful tool for data manipulation. Here's how:
1. **Launch Power Query**: Click on the 'Data' tab, then 'Get & Transform Data', and finally 'From Table/Range'.
2. **Create a new column**: In the 'Home' tab of the Power Query Editor, click on 'New Column'. In the formula bar, enter the following formula: `= Table.Column([First Name], "Last Name")`. This creates a new column with last names.
3. **Sort the data**: Click on the 'Home' tab again, then 'Sort'. In the dropdown menu, choose 'Sort by Column'. Select the last name column and choose 'Descending' or 'Ascending' depending on your preference.
4. **Close & Load**: Once you're satisfied with the sorted data, click on the 'Home' tab, then 'Close & Load'. Choose 'Table' and click 'OK'.
Your data is now sorted by last name, and rows are kept together.
Remember, keeping your data organized is key to efficient analysis. Sorting by last name while keeping rows together ensures your dataset remains easy to navigate and understand. Happy sorting!