Skip to main content
 

How to sort cells by last character or number in Excel?

Author: Kelly Last Modified: 2024-09-24

It is easy to sort cells by the first character in Excel. But when you need to sort cells by the last character or number in Excel, how could you do it? This article is going to show you some easy ways to sort cells by last character or number in Excel quickly.

Sort by last character or number with Right Function

An example may be easy to understand. The following ways will show you how to sort the cells in the Column A by their last characters.

If we can extract the last characters from each cell, it will be easy to sort the cells by their last characters. Luckily, Microsoft Excel's Right function supports extracting the last letter or number form cells.

1.  Select a blank cell besides the column, says Cell B2, enter the formula of =RIGHT(A2,1), and then drag the cells's Fill Handle down to the cells as you need.
Formula entered to get the last character from each cell

2. Keep selecting these formula cells, and click Data > Sort A to Z or Sort Z to A. In the opening Sort Warning dialog box, check Expand the selection option and click Sort button. See screenshot:
Sort Z to A option on the ribbon and the Sort Warning dialog box

3. Now data has been sorted. Please delete the formula cells as you need

Then you will see the cells in original Column A are sorted by their last characters.

Easily sort by last name/word in cells in Excel

Kutools for Excel's Advanced Sort utility supports sorting data by many flexible scenario/methods, such as sort by text length, sort by frequency, sort by last name, etc.


Kutools for Excel's Advanced Sort interface and use case example

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now

Sort by last character or number with VBA

You may also think of reverse the cell contents before sorting them by their last characters. Actually here is a VBA macro can help you.

1.  Hold down the Ctrl + F11 key to open the Microsoft Visual Basic for Application window.

2.  Click the Insert >> Module, and paste the following VBA code on the new Module window:

VBA: Extract the last character form a cell

Public Function RevStr(Rng As Range)
RevStr = StrReverse(Rng.text)
End Function

3.  Go back to the Microsoft Excel window, enter the formula of =RevStr(A1), and drag the cell's Fill Handle to the cells as you need.
Formula entered to reverse characters in each cell

4.  Click one of three Sort buttons under the Data button, and in the opening dialog box check the Expand the selection option and click the Sort button.
Sort Z to A option on the ribbon and the Sort Warning dialog box

5. Delete the Column B.

Now it sort all cells in the column a by their last characters.


Sort cells by last characters or numbers with Kutools for Excel

If we can reverse all characters’ order in cells, then we can sort these cells by the last character easily. Kutools for Excel’s Reverse Text Order utility can help you solve it easily.

Kutools for Excel - Packed with over 300 essential tools for Excel. Enjoy permanently free AI features! Download now!

1. Select the cells that you will sort by last character, and click Kutools > Text > Reverse Text Order.

Reverse Text Order option on the Kutools tab on the ribbon

2. In the opening Reverse Text dialog box, check Noting option and click OK button.
Reverse Text dialog box and result

3. Now all characters are reversed in selected cells. Keep selecting these cells, and click Data > Sort A to Z or Sort Z to A. In the opening Sort warning dialog box, check Expand the selection option and click Sort button. See screenshot:
Cells are sorted by last character

4. Now cells have been sorted by last character, and we need to restore characters’ order in these cells by repeating step 1-2.

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now


Demo: sort cells by last character or number in Excel

Kutools for Excel: Over 300 handy tools at your fingertips! Enjoy permanently free AI features! Download Now!

Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!