Solved

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

Posted on 2012-03-19
2
236 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
2 Comments
 
LVL 6

Accepted Solution

by:
Kyle_Davies earned 500 total points
ID: 37737811
0
 
LVL 3

Expert Comment

by:DaFranker
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

803 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