Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to sort strings by a second or third character in Excel?

In Excel, we usually sort data in ascending or descending order by the Sort utility. But the Sort utility only sorts the data based on the first character. How about sorting strings with the second or third or nth character as below screenshot shown? In this article, I introduce some tricks on solving this job.

General Sort  Sort by the second character
doc sort by nth character 1 doc sort by nth character 2

Sort strings by the second character with formula

Sort strings by middle characters with Text to Columns


Sort strings by the second character with formula


To sort strings by the second or third character, you need a helper column.

1. Select a cell next to the strings you want to sort, and type this formula =RIGHT(A1,LEN(A1)-1), (A1 is the cell you use, -1 indicates to remove the first character from left) press Enter key and drag fill handle over the cells which needed this formula. Now the strings have been extracted except the first one character.
doc sort by nth character 3

2. Keep formula cells selected, click Data > Sort A to Z, next check Expand the selection option and click the Sort button in Sort Warning dialog. See screenshot:
doc sort by nth character 4

3. The data has been sorted by the second character. You can remove the helper column.
doc sort by nth character 5


Sort strings by middle characters with Text to Columns

If you want to sort text strings only by several middle characters, you can use the Text to Columns function.

For instance, sort the phone numbers by middle two digits as below screenshot shown.

doc sort by nth character 6 doc arrow right doc sort by nth character 7

 

1. Select the strings you use, and click Data > Text to Columns.
doc sort by nth character 8

2. In the Convert Text to Columns Wizard dialog, check Delimited option in the first one step, click Next to check Other option in Delimiters section, and type the separator which is used to split the numbers in the textbox, then click Next to go to last step, and select a location to place new data. See screenshot:

doc sort by nth character 9
doc sort by nth character 10
doc sort by nth character 11

 

3. Click Finish, and the text strings have been split into columns, and select the column data which you want to sort strings by, click Data > Sort A to Z, and check Expand the selection option in the Sort Warning dialog. See screenshot:
doc sort by nth character 12

4. Click Sort. Now the text strings have been sorted by middle characters, you can remove the helper columns.
doc sort by nth character 13

Tip: If the text string has no separator to split characters, you can use this formula =MID(A17,3,2) to extract only the middle characters, then sort. In the formula, A17 is the cell you use, 3 indicates to extract the number third character from left, 2 means to extract 2 characters.
doc sort by nth character 14



Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.