Software

Use Word's Replace to transpose a column of names

Transposing a list of names is a fairly easy task for Word's Replace feature. Susan Harkins shows you how it works.

You'll often see a column of names entered in a Word document either as a list or part of a table. Listing the names is no problem, but changing their order after they're entered could be. For instance, let's say your document contains a list of names entered in firstname lastname format, but you want them in lastname, firstname format. Do you have to re-enter them? No, there's a simple wildcard trick you can use with Word's Replace feature that will take care of the transposing for you.

To get Word to transform a list or column of names, do the following:

  1. Select the list of names you want to transpose.
  2. From the Edit menu, choose Replace. In Word 2010, click Replace in the Editing group on the Home tab.
  3. Click the More button and check the Use Wildcards option. This is an important step—if you miss it, this technique won't work.
  4. In the Find What control, enter (<*>) (<*>), with a space character between the two sets.
  5. In the Replace With control, enter the following characters \2, \1, with a space character before the second slash character.
  6. Click Replace All. Word will transpose the first and last names and separate them with a comma character.
  7. When Word asks you to expand the search, click No, and then Close to return to the document.

Wildcard explanation

Once you understand the wildcards, the whole trick is easily exposed:

  • (): The parentheses aren't true wildcards, not in a matching sense. They allow you to divide a pattern into logical sequences.
  • <>: The brackets mark the beginning and ending of a word or phrase.
  • \: The slash character replaces characters, and is used with a number that specifies a bracketed component (above).
In this case, the Find What code splits the two names into two separate sequences. The \2 component in the Replace What code replaces the contents of the first sequence with the contents of the second sequence. The \1 component replaces the contents of the second sequence with the contents of the first. As you can see, you're not limited to just transposing first and last names. With these wildcard tools, you can rearrange quite a bit of content!

What's the most interesting wildcard code you've used and how to you apply it?

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

13 comments
stapleb
stapleb

What a wonderful tip Susan. I can see a number of situations where this would be useful. Oh, and a tip for bd1235, in Word all you have to do to fix the text after selecting it is to hold down Ctrl and press the Spacebar. You can then fix graphics as required. And, I'm with you, when selecting any Internet screen I always work from the bottom up, for some reason it does make it so much easier.

erudites1
erudites1

Valuable information. I wish there was a good way to print it.

LocoLobo
LocoLobo

Although I will admit I added a comma after the \1 in my first attempt. Thanks!

kcockfield
kcockfield

Thank you so much for the Ctrl Spacebar tip -I often copy from this site & save in Word doc for later reference and do a tidy up. What an efficient way to tidy up quickly.

nancy.boone
nancy.boone

When a copied article is pasted into a Word document and the text is gray and all capitals, undo the paste. Instead of using a plain Paste for the copied information, use Paste Special and change from HTML format to Formatted Text(RTF). The text is nicely formatted and hyperlinks function. The size of the graphics can be adjusted as needed.

bd1235
bd1235

Many of these articles also come as a downlload PDF. If so then just print it that way. SH does not seem to offer that option. Maybe she should. She does offer valuable tips and I do like to save them. Another way: if you are reading SH's articles then you probably have Word. Just select the text and images of the article and paste it into Word. I find it easier to select from the bottom to the top of the article. It seems less difficult. Once you have it in Word then you see that all is not easy. The text is all capitals and it is a pale grey. Do a Select All and fix the text colour so you can see what you are doing. Then do a convert to Sentence Case. This gives you lower case except for the capital at the beginning of the sentence. Fix up any problems that this conversion has caused. Go through the document and if the images are small then flow the text around them (hint: Right Click the image) and do other tricks, as needed, to make your doc look OK. Then save and / or print it.

steve
steve

I've been a Word "power user" (and Tech support specialist) since Word 5 for DOS and I've never seen that before. in the past I've exported to Excel, parsed the data into two columns and cut and paste the columns before re-exporting to Word, I've written macros in VBA to find the space and do the swap - now I have a "native" Word technique. Thanks very much! I don't think this technique will work where the list contains some triple names (Jean Michel Jarre sort of thing) or where some names have a title (Mr Joe Bloggs) but the rest of the list is a standard two names. Manual editing of the list required, or can someone think of a better way?

stapleb
stapleb

from the Keyboard Queen. Ctrl + Space removes ALL Character formatting and returns it to the current style. Change the style and everything is altered. Tip Ctrl + Q removes ALL Paragraph formatting and is another time saver. BTW it's Melbourne Kensington so I'm waving to you.

stapleb
stapleb

Whoops, I missed the bit about it all being in capitals. For all those who like to know, like to use their keyboard, or whatever else your like is, if the text is highlighted Shift + F3 will scroll through a number of the different Convert Case options.

ssharkins
ssharkins

I don't know how you could apply this if the names are in a consistent format -- for instance, some having a middle initials, others not -- probably a work around, but I haven't worked on one.

semi-adult
semi-adult

This is 'regular expressions' technology, often called 'regex', which has been around forever. The MS variant here has a few quirks, but it's still a great tool. You'll want to get a good reference on this... I'd recommend the O'Reilly book, and there's quite a bit online... then see just how much of RE works in Word. There's no 'standard' -- everyone has a flavor. RE allows this variable replacement trick, plus conditional operations that could do things like you suggest, perhaps even the variable-count name edit. Assuming the MS flavor allows all the features is, however, a bit of a caveat. You may want to investigate the RE capacities of VBA these days too, which will let you do some pretty stupendous things.

Andy P Roberts
Andy P Roberts

You can move surnames to the end when there are middle names or middle initials using (*) ([! ]@)^13 in Find text and \2, \1^p in the Replace With. The Find text is best understood in reverse order - ^13 is the Carriage Return which equates to word's "End of Paragraph" except that it looses any formatting held in the End of Paragraph marker - ([! ]@) repeats "not space" ([! ]) as many times as in necesary before the Carriage Return (@) - before that is a space (required before the surname - it wont work for J.Smith) - (*) is all characters before that last space This ok but has to be used with care - a line/paragraph with a single name in it, that is blank or with a space character at the end will not be handled correctly by this code.

ssharkins
ssharkins

if the names are NOT in consistent format...