Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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.
Written by Allen Wyatt (last updated May 10, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Reordering Last Name and First Name.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
When you need to pull information from a lot of different worksheets into a single worksheet, it can be baffling to ...
Discover MoreThe primary way you signify that you are entering a formula is to start a cell entry with an equal sign. The equal sign ...
Discover MoreWhen you copy a formula from one cell to another, Excel normally adjusts the cell references within the formula so they ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-01-28 16:09:46
werner
doesn't go
2018-01-01 03:43:26
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
...."...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
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
This seems much simpler to me;
Dim myArry() as string
myArry=split ("A1",",")
A1=myArry(1) & "," & myArry(0)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments