Avatar of brothertruffle880
brothertruffle880
Flag for United States of America asked on

Word 2003, 2007, 2010 - Sorting the SECOND or THIRD word in a series of words

I have a table with the first and last names of people.  I would like to sort by last name --which is the second word inside of the cell.

To further complicate this, some people have a middle initial which I would like to ignore.

How can i sort by last name in a table cell where some people have middle initials?
Microsoft Word

Avatar of undefined
Last Comment
Frank White

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kyle Davies

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Frank White

With VBA, something like this is rather simple. See this sample Split() function for details on how to parse a single string of text and return an array with the words in it.

If you call for the last element of the string array, you'll have the last word of the line.

For the actual sorting, the easiest would probably be to have a new column containing only the last name, put there by macro or with a UDF. However, it's also possible to have a single macro handle the parsing and sorting all at once, but that also means adding a sorting algorithm to the VBA code, which might not be so simple if you've never done such things before (especially if you want the sorting to happen "inplace", which seems to be the case).
Your help has saved me hundreds of hours of internet surfing.
fblack61