Skip to main content
 

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

Author: Sun Last Modified: 2024-08-13

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
a screenshot showing the general sort a screenshot of data sorted by the second character

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.

a screenshot of removing the first letter with formula in a helper column

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:

a screenshot of shorting the data

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

da screenshot showing the sorting results


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.

a screenshot showing the original data a screenshot of a right arrow a screenshot of sorting by middle characters

1. Select the strings you use, and click Data > Text to Columns.

a screenshot of enabling the Text to Columns feature

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:

a screenshot of selecting Delimited in the wizard
a screenshot of specifying a delimiter in the wizard
a screenshot of selecting a destination cell

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:

a screenshot of expanding the selection

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

a screenshot showing the sorted result

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.
a screenshot of extracting the middle characters with formula if the text string has no separator


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!