Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Ignoring Selected Words when Sorting.

Ignoring Selected Words when Sorting

by Allen Wyatt
(last updated March 17, 2017)

5

Arn has a need to exclude certain words when sorting a column. For instance, he is trying to exclude 'The' when sorting a list of movie titles, so that "Alpha, Charlie, The Bravo" would sort as "Alpha, The Bravo, Charlie."

There is no built-in way to do this. The best solution is to set up an intermediate column for your data. This column can contain the modified movie titles, and you can sort by the contents of the column. For instance, if column A contains your original movie titles, you could fill column B with formulas, such as this:

=IF(LEFT(A1,4)="The ",MID(A1,5,LEN(A1)-4),A1)

This formula will strip the word "The" (with its trailing space) from the start of the line. If you want to add the word "The" at the end of the string, then you could modify the formula in the following manner:

=IF(LEFT(A1,4)="The ",MID(A1,5,50),A1) & ", The"

If you wanted to delete all instances of the word "the" without regard to where it appeared in the title, you could use the following instead:

=SUBSTITUTE(A1,"the ","")

Sorting, again, would be done by the results shown in column B. This will give the list in the desired order.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3892) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Ignoring Selected Words when Sorting.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Format Painter Shortcut

Need a way to copy formatting using the keyboard? Word has a great one, and it doesn't involve the Format Painter or the ...

Discover More

Templates and Page Setup

Templates are a great way to share styles, macros, and other settings among various documents. One thing that isn't shared ...

Discover More

Using the Control Panel to Remove Programs

Removing programs that you no longer need can help to free up system resources and keep your system clean and running ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

MORE EXCELTIPS (MENU)

Sorting Huge Lists

Got a huge amount of data you need to sort in a worksheet, but Excel doesn't seem to be sorting it correctly? Here's some ...

Discover More

Importing Custom Lists

Custom lists are handy ways to enter recurring data in a worksheet. Here's how you can import your own custom lists from a ...

Discover More

Sorting an Entire List

Need to sort all the data in a table? Here's the fastest and easiest way to do it.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three minus 1?

2016-01-15 02:56:47

Jesse

Your example formula:
=IF(LEFT(A1,4)="The ",MID(A1,5,50),A1) & ", The"
is actually incorrect. It removes "The" if it's there, but adds ", The" only if the original string did NOT start with 'The'.

Should be:
=IF(LEFT(A1,4)="The ",MID(A1,5,50) & ", The",A1)


2015-09-05 11:47:48

Anthony E

Hey Jack!

To your formula -- how do you do the same for the letter "A," and the word "An?"

I want to do it for all 3, except I am having an issue in excel. I think it is because of how many parenthesis I put in the formula. Is there anyone you can send me an entire "IF" FORMULA?

Thanks!


2015-04-18 14:00:37

Bill

Perfect solution to my problem! Thank you!


2012-08-04 05:03:17

Jack

This is an excellent tip. This is the full formula I used and then filled down:

=IF(LEFT(A2,4)="The ",MID(A2,5,LEN(A2)-4)&", The",A2)


2012-08-03 15:44:06

Juan

It would be helpful if you include a particular example to apply the formula. Thanks!


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing