Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Reordering Last Name and First Name.

Reordering Last Name and First Name

by Allen Wyatt
(last updated December 12, 2015)

12

You may have a worksheet containing many cells with names that are in LastName, FirstName MI format. A common example of this would be an Excel worksheet designed to work as an expense account reporting form. You may want to convert these employee names into standard format, i.e. FirstName MI LastName. Performing this operation on more than a handful of cells can become quite cumbersome.

To make the conversion job easier, you can use a handy formula that rearranges the parts of the name for you. Assume that cell A1 contains the name Doe, Jane Q. and you want the conversion (Jane Q. Doe) to appear in cell B1. Place the following formula in B1:

=RIGHT(A1,LEN(A1)-LEN(LEFT(A1,FIND(",",A1)
-1))-2) & " " & LEFT(A1,FIND(",",A1)-1)

The formula works by breaking the string based on the placement of the comma. The formula will also work with suffixes and multiple middle initials as long as there is one and only one comma present in the source cell.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12042) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Reordering Last Name and First Name.

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

Patterns of Numbers with a Formula

Want to create a sequential pattern using formulas? It's easy to do if you take a look at how your data repeats. This tip ...

Discover More

Understanding SmartArt

SmartArt provides a way to add classy presentation graphics to your document. Here's a high-level explanation of what you ...

Discover More

Zooming With the Keyboard

Excel doesn't provide a keyboard shortcut that allows you to zoom in or out on your workbook. It is easy, however, to ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Shortcut for Viewing Formulas

If you need to switch between viewing formulas and viewing the results of those formulas, you'll love the keyboard ...

Discover More

Saving Common Formulas

Got some formulas you slaved over and want to use in lots of workbooks? This tip presents some helpful ideas on how you ...

Discover More

Determining If a Value is Out of Limits

Need to figure out if a value is outside of some arbitrary limit related to a different value? There are a number of ways ...

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

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. Maximum image size is 6Mpixels. 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 five more than 8?

2018-01-01 03:43:26

Alan Elston

Thanks Rick
I see also that the address substitution is not necessary, when I know the address. But I found that @ substitution from an earlier post of yours quite neat so I left it in to remind me.
I must also note that when inside a function nested in a [ ] then quotes are possible. I have probably overlooked that in the past. I have probably overlooked that as a major advantage of the Evaluate(“ “) over the “shorthand” [ ] is often given as being able to …..“…build up a string, whereas you cannot do that with the [ ] …”...
In fact now that I recall, I think I noticed in a post of yours before .. and noted then the less tricky building up of the quotes in the [ ] compared with in the Evaluate(” “)
( – I was away all Summer from the computer so must brush up a bit :) )_ ….
_.....
For a [ ] you put in it what you put in a cell
For a Evaluate(“ “) you have to arrange that the evaluated string ends up looking like what you have in a cell … that can be a nightmare then with double - doubled - """" - """" & :- ) quotes and the such.. :-)

Alan


2017-12-31 11:27:09

Rick Rothstein

>> Now apply that one liner code in this form:
>>
>>Sub RangeEvaluate()
>> Let Range("B20:B25").Value = Evaluate(Replace("IF({1},TRIM(MID(@&"" ""&@,FIND("","",@)+1,LEN(@))))", "@", Range("A20:A25").Address))
>>End Sub

Alan... if the ranges are fixed and non-changing, then your one-liner can be "simplified" by using the alternative syntax for the Evaluate function.

Sub RangeEvaluate()
[B20:B25] = [IF({1},TRIM(MID(A20:A25&" "&A20:A25,FIND(",",A20:A25)+1,LEN(A20:A25))))]
End Sub


2017-12-30 03:01:48

Alan Elston

...."...Excel array formula in disguise..."... That is a nice description, Wiily, I like that :-)
see you in 2018


2017-12-29 12:22:46

Willy Vanhaelen

@Alan Elston
It can even simpler: just select the range and run my one liner, it will process all cells in the selected range at once. So you can use it on a single cell or with any range without having to change it. And you are right this one liner runs much faster than a macro using a loop. In fact it is a sort of Excel array formula "in disguise" :-)

I wish you the best for 2018.

Willy


2017-12-25 05:47:07

Alan Elston

Just for anyone that may not have noticed.. The beauty of that Evaluate Range type one liner is that it works over a Range of more than one cell, ( and often it works a lot quicker than a more typically seen code which would loop through that range applying at each loop a formula ).

So, as example, say the cells A20 to A25 look something like this:
Doe, Jane Q
Elston,Alan M
Rothstein, Rick
Elstein,Doc. Alaen
Halen,Wolfgang Van
Vanhaelen, Willy

Now apply that one liner code in this form:

Sub RangeEvaluate()
Let Range("B20:B25").Value = Evaluate(Replace("IF({1},TRIM(MID(@&"" ""&@,FIND("","",@)+1,LEN(@))))", "@", Range("A20:A25").Address))
End Sub

You should then see over the range B20 to B25
Jane Q Doe
Alan M Elston
Rick Rothstein
Doc. Alaen Elstein
Wolfgang Van Halen
Willy Vanhaelen

Merry Xmas Willy and Rick, and best wishes for the New Year..
Alan


2017-12-25 02:31:20

Rick Rothstein

@Willy,

And here is a one-liner UDF (user defined function) should anyone want to go that route...

Function Reorder(S As String) As String
Reorder = Trim(Mid(S & " " & S, InStr(S, ",") + 1, Len(S)))
End Function


2017-12-24 13:51:22

Willy Vanhaelen

@Rick Rothstein

Brillant !

Here is even a one-liner based on your formula :-)

Sub Reorder()
Selection = Evaluate(Replace("IF({1},TRIM(MID(@&"" ""&@,FIND("","",@)+1,LEN(@))))", "@", Selection.Address))
End Sub


2017-12-23 05:31:16

Rick Rothstein

@ Willy Vanhaelen and Sara Gonzalez,

Here is a shorter formula that will work whether there is a space after the comma or not...

=TRIM(MID(A1&" "&A1,FIND(",",A1)+1,LEN(A1)))


2017-12-23 05:26:42

Rick Rothstein

Here is a shorter formula which will produce the same results as the one shown in this article...

=MID(A1&" "&A1,FIND(" ",A1)+1,LEN(A1)-1)


2016-12-10 09:29:00

Willy Vanhaelen

@Sara Gonzalez

This shorter formula will do the job whether or not there is a space after the comma.

=TRIM(MID(A1,FIND(",",A1)+1,LEN(A1)))&" "&LEFT(A1,FIND(",",A1)-1)


2016-12-09 14:21:47

Sara Gonzalez

What if my text isn't seperated by a space after the comma. For example our program generates the name as follows last,first with no space between the comma and first name. So when I use this formula it chops it up. So I would have to manually enter the space in order for the formula to work. Any quick fixes.


2016-03-31 08:05:21

Louis LAFRUIT

This seems much simpler to me;
Dim myArry() as string
myArry=split ("A1",",")
A1=myArry(1) & "," & myArry(0)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.