Sort Excel Names While Ignoring Punctuation and The
Question details
Sort names and terms by a normalized key that ignores punctuation, spaces, and a leading standalone “The.”

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- The user wants a letter-by-letter sort while keeping the original names and terms visible.
- Observed behavior
- The desired order ignores punctuation and spaces and treats a leading “The” as a prefix rather than part of the sort key.
Make sure your names have a column header and check that Power Query is available under Excel’s Data tab. The example below uses a column named Name and keeps English letters and digits in the sort key.
Create and sort by a Power Query helper column
Use a normalized sort key while preserving the original text in Excel.
This example removes a leading standalone “The” and retains only English letters and digits in the key. It does not preserve accented or other non-English letters; adapt the character list if you need them.
Select a cell in your data, then choose Data > From Table/Range. Confirm that the table has headers.
In Power Query Editor, choose Add Column > Custom Column, name it Sort Key, and enter the following formula. Replace [Name] if your source column has a different header: let chars = {"a".."z", "A".."Z", "0".."9"}, s = if [Name] = null then "" else Text.From([Name]), p = Text.PositionOfAny(s, chars), t = if p = -1 then "" else Text.Range(s, p), hasThe = Text.Lower(Text.Start(t, 3)) = "the" and (Text.Length(t) = 3 or not List.Contains(chars, Text.Middle(t, 3, 1))), body = if hasThe then Text.Range(t, 3) else t in Text.Lower(Text.Select(body, chars))
Open the Sort Key column’s filter menu and select Sort Ascending. The Name column remains unchanged.
Choose Home > Close & Load to return the sorted table to Excel.

Build a helper sort key in WPS Spreadsheets
Use helper columns to remove common punctuation and a leading standalone “The,” then sort the original names by the resulting key.
- 1. Open your list: Open the workbook in WPS Spreadsheets. Place the names under a header in column A and add headers for helper columns B, C, and D.
- 2. Replace common punctuation: In B2, enter =TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,CHAR(34)," "),"'"," "),"."," "),","," "),"-"," "),"("," "),")"," ")). This handles quotation marks, apostrophes, periods, commas, hyphens, and parentheses; add substitutions for other punctuation as needed.
- 3. Remove the prefix and spaces: In C2, enter =IF(OR(LOWER(B2)="the",LEFT(LOWER(B2),4)="the "),MID(B2,5,LEN(B2)),B2). In D2, enter =LOWER(SUBSTITUTE(C2," ","")), then fill B2:D2 down for all rows.
- 4. Sort the complete list: Select the full table, including the original names and helper columns. Choose Data > Sort and sort column D from A to Z.

Frequently Asked Questions
Can Excel ignore punctuation using its standard sort settings?
Excel does not provide a general sort rule for ignoring arbitrary punctuation and prefixes. Create a helper key in Power Query or with formulas, then sort by that column.
Will the Power Query formula remove “The” from “Theodore”?
No. The example removes “The” only when the next character is not an English letter or digit, or when “The” is the entire remaining text.
What happens when two names have the same sort key?
They sort together. In Power Query, add a secondary sort using another column if you need a consistent order for those entries.
Can I use this Power Query method on a Mac?
Check Excel’s Data tab for Power Query and the ability to create and edit queries. Availability and features depend on your Excel version and update channel.




