How to sort cells by last character or number in Excel?
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.
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
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.
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:
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.
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)
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.
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.
5. Delete the Column B.
Now it sort all cells in the column a by their last characters.
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 as below screenshot shown:
Kutools for Excel - Combines more than 300 Advanced Functions and Tools for Microsoft Excel
1. Select the cells that you will sort by last character, and click Kutools > Text > Reverse Text Order.
2. In the opening Reverse Text dialog box, check Noting option and click OK button.
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:
4. Now cells have been sorted by last character, and we need to restore characters’ order in these cells by repeating step 1-2.
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 4 months agoThanks! This was very helpful!
To post as a guest, your comment is unpublished.· 1 years agoThanks! Great article
To post as a guest, your comment is unpublished.· 1 years agoGreat tutorial, very helpful for my project. Thank You
To post as a guest, your comment is unpublished.· 4 years agohii
can u help how to aarange the the project codes in specifed order according to there last 3 digt code all 026 should colum by col
To post as a guest, your comment is unpublished.· 5 years agoMy easy suggestion
Suppose the column that you want to sort is titled PRODUCT_CODE
Highlight the required cells (PRODUCT_CODE)
In DATA option, click on FILTER. Beside the top cell on PRODUCT_CODE, you will see the filter option, when you click on it, the drop down pane will have the option of TEXT FILTERS.
In TEXT FILTERS you will get the ENDS WITH option , or you can use the CONTAINS option. This will sort with exactly what criteria you require.
eg: PRODUCT_CODE List contains
if you use the highlight the column and FILTER it by ends with K, the result will give
Hope this helps you out guys!