# Worksheet Custom Sort

0
1627

The ExcelHelpDesk Support team received the following request for help

### Problem – Sort by Last Two Digits

I’m trying to find a formula where I can take the last 4 digits of the social security and sort it by using the last two digits only. For example:
0001
0102
1103
0104
2105
And so on. Any help would be greatly appreciated. Thank you…

For this problem we received a copy of the workbook. We then used a formula to extract the last two digits of the text string. From there we sorted the worksheet by the extracted digits to acheive the result. Find below a screen shot of the un-sorted list, the formula used and then the sorted list.

Let us know if you need help in applying the sample to your situation.

### Sample Un-sorted List

See below an example of the data provided for sorting ### Step 1 – Include RIGHT Formula

Now before we can sort this list by the last two digits we need to extract the digits from the existing string. We can do this using the RIGHT formula on the existing string. See the formula for the first row of the sample sheet below. ### Step 2 – Now Sort the new Column

Now simply drag that formula down until the last value in Column B is extracted. Then select the entire range from A2:C592 and sort the range using the new column of two digits in ascending order. See below for the sorted result. If you have a question on this post for the Excel Help Desk team or have something you would like to share on this topic then please leave a comment