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


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
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.