Solved

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

Posted on 2012-03-19
2
240 Views
Last Modified: 2012-04-17
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?
0
Comment
Question by:brothertruffle880
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
Kyle Davies earned 500 total points
ID: 37737811
0
 
LVL 3

Expert Comment

by:Frank White
ID: 37737985
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).
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question