How to flip the first and last name in cells in Excel?

Let's say you get a roster of names in one column, however, you need to flip the first name and last name in cells. Normally you will get into one cell and cut the last name, and then paste it before the first name, or retype the name again. It will be time-consuming and tedious if you use these traditional methods. Actually, there are several easy ways to flip or reverse the first name and last name in a single column quickly.

Flip the first and last name in a column with a function

Flip the first and last name in a column with VBA

Flip the first and last name in a column with Kutools for Excel

Supposing you have a column of names, and you need to flip the first and last name as below screenshot shown:

doc-flip-first-last-names1 -2 doc-flip-first-last-names2

arrow blue right bubble Flip the first and last name in a column with a function


We can use one of Excel's formulas to flip the first and last name quickly in a column with following steps:

Step 1: Enter the formula =MID(A1&" "&A1,FIND(" ",A1)+1,LEN(A1)) in a blank cell, says Cell C1. See screenshot:

doc-flip-first-last-names3

Step 2: Select the range of C1:C10, and click the Home > Fill > Down. Then you will see the first name are last name are inversed. See screenshot:

doc-flip-first-last-names4

Step 3: As they are formulas, when copy them to other cells, please paste as values.


arrow blue right bubble Flip the first and last name in a column with VBA

You can also use VBA macros to flip the first and last name in a column quickly.

Step 1: Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

Step 2: Click Insert > Module, and paste the following macro in the Module window.

Sub FlipName()
'Updateby20131126
Dim Rng As Range
Dim WorkRng As Range
Dim Sign As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Sign = Application.InputBox("Symbol interval", xTitleId, " ", Type:=2)
For Each Rng In WorkRng
    xValue = Rng.Value
    NameList = VBA.Split(xValue, Sign)
    If UBound(NameList) = 1 Then
        Rng.Value = NameList(1) + Sign + NameList(0)
    End If
Next
End Sub

Step 3: Press the F5 key to run this macro. In the popping up KutoolsforExcel dialog box, select the range to flip, and then click the OK button. See screenshot:

Step 4: In the following popping up dialog box, please define an interval symbol (such as a space), and then click the OK button. See screenshot:

Now the first name and last name in selected range are flipped.


arrow blue right bubble Flip the first and last name in a column with Kutools for Excel

With Kutools for Excel’s Reverse Text Order, you can quickly reverse order of the text in the cells.

Kutools for Excel includes more than 120 handy Excel tools. Free to try with no limitation in 30 days. Get it Now.

If you have installed Kutools for Excel, please do as following steps:

Step 1: Select the range that you want to reverse the first and last names.

Step 2: Click Kutools > Text > Reverse Text Order, see screenshot:

Step 3: In the Reverse Text dialog box, specify a separator your selected text string using, (in this case, I select Space option) and then click the OK button. You can see the results in the Preview pane. See screenshot:

doc-flip-first-last-names6

Now all the first names and last names in the selected range have been reversed.

Note: Checking Skip non-text cells to prevent you reversing the numbers in selected range.

If you want to know more about this feature, please click Reverse Text Order.

 

Recommended Productivity Tools

Office Tab

gold star1 Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.

Kutools for Excel

gold star1Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!

gold star1200 New Features for Excel, Make Excel Much Easy and Powerful:

  • Merge Cell/Rows/Columns without Losing Data.
  • Combine and Consolidate Multiple Sheets and Workbooks.
  • Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
  • Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
  • More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

Screen shot of Kutools for Excel

btn read more btn download btn purchase

Comments  

Permalink 0 Stacy
None of this Works, except for what this person is selling
2013-12-16 00:47 Reply Reply with quote Quote
Permalink +9 Raymond
The first formula works perfectly.
2013-12-26 14:56 Reply Reply with quote Quote
Permalink 0 CJC
I understand what each part of the formula does (MID, FIND, and LEN), but I don't understand why it's actually flipping the names. Can someone please explain that to me?
2014-01-14 14:01 Reply Reply with quote Quote
Permalink +3 Mike Gagne
Quoting CJC:
I understand what each part of the formula does (MID, FIND, and LEN), but I don't understand why it's actually flipping the names. Can someone please explain that to me?


Here's the formula being used:
MID(A1&" "&A1,FIND(" ",A1)+1,LEN(A1))

The Mid function has these components:
Mid("text to use", where to start, num of chars to select)

It works by taking the contents of A1 and putting two copies of it together separated by a space (i.e. A1&" "&A1 = "Jim Green Jim Green".)

The next step then skips the first word (i.e. Find(" ", A1)+1 = "Jim ", so in net effect leaves you with "Green Jim Green" to work with.)

The final step selects the length of the orginal string (i.e. Len("Jim Green") = 9) from the remaining portion of the concatenated string less the first name (i.e. "Green Jim Green")

Hopefully that makes sense.
2014-05-06 14:21 Reply Reply with quote Quote
Permalink +2 Mike Gagne
Sadly, the original formula doesn't work correctly if the name includes a middle initial or middle name. So, "Jim R Green" gets you "R Green Jim" when you really want "Green Jim R".

The formula to allow for that to happen is:
=MID(A1&" "&A1,IF(LEN(A1) -LEN(SUBSTITUTE (A1," ",""))=1,FIND(" ",A1)+1,FIND(" ",A1,FIND(" ",A1)+1)+1),LEN(A1))

What I've done with the original formula is just add a test to see if the original name contains more than 1 space and if so, begin my mid function with the second space. Note that it's still not perfect because it doesn't take into account "Jr.", "Sr." or "III", etc. being after the last name, but it's better.

An additional thing to keep in mind is if your data isn't 100% clean and contains leading or trailing spaces, like "Jim R Green ", you'll need to use the TRIM command to clean it up. If you don't, it will throw off the count of spaces and give you a "#value!" error. Use this to ensure no leading or trailing spaces affect your results:

=MID(TRIM(A1)&" "&TRIM(A1),IF(L EN(TRIM(A1))-LE N(SUBSTITUTE(TR IM(A1)," ",""))=1,FIND(" ",TRIM(A1))+1,F IND(" ",TRIM(A1),FIND (" ",TRIM(A1))+1)+1),LEN(TRIM(A1)))

You can also alter the formula to include the comma between the last and first names, as in "Green, Jim R", by using this:

=MID(TRIM(A1)&", "&TRIM(A1),IF(L EN(TRIM(A1))-LE N(SUBSTITUTE(TR IM(A1)," ",""))=1,FIND(" ",TRIM(A1))+1,F IND(" ",TRIM(A1),FIND (" ",TRIM(A1))+1)+1),LEN(TRIM(A1))+1)

Hope that helps out some!
2014-05-06 14:22 Reply Reply with quote Quote
Permalink 0 JS
While the original formula doesn't work for multiple first names or first name + middle name initials (the aforementioned Jim R. Green, or Lee Harvey Oswald, for example), it does work correctly for multi-part surnames, e.g. James Van Der Beek -> Van Der Beek James. If you have one or two instances of people with both multiple first names or middle names combined with a multi-part surname, you're probably best off handling those manually. Or trimming away the extra middle names, or saving the first names and last names in separate columns to begin with, then hiding those columns and combining them however you want for display.
2014-05-08 09:16 Reply Reply with quote Quote
Permalink +1 Mike Gagne
That's a really good catch JS, one example that I hadn't thought of testing.

There is another work around that could be done to help with this issue and that is to use a non-breaking space to separate multi-part last names. You may have seen &NBSP used in HTML code. You can insert a non-breaking space into your cell by holding the ALT key and typing the numbers "0160" using the keypad.

I tried it and it works great.
2014-05-09 16:33 Reply Reply with quote Quote
Permalink 0 Joel
Please help

What if multiple First name or surname

Example

Nick Van Exel
should appear as VanExel, Nick

Luis Alfred D. Chua
should appear as Chua, Luis D.
Chua, Alfred D.

Jason D. Lee-Parks
should appear as LeeParks, Jason D.
2014-07-19 07:42 Reply Reply with quote Quote
Permalink 0 Prashant Kulkarni
Thanks Mike Gagne its helps me lot. i have big data base of full name i have to sort it by last name first. its give me very big help on that work. thank you again.
:lol:
2015-08-28 10:13 Reply Reply with quote Quote
Permalink 0 William
Quoting Mike Gagne:
Sadly, the original formula doesn't work correctly if the name includes a middle initial or middle name. So, "Jim R Green" gets you "R Green Jim" when you really want "Green Jim R".

The formula to allow for that to happen is:
=MID(A1&" "&A1,IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=1,FIND(" ",A1)+1,FIND(" ",A1,FIND(" ",A1)+1)+1),LEN(A1))

What I've done with the original formula is just add a test to see if the original name contains more than 1 space and if so, begin my mid function with the second space. Note that it's still not perfect because it doesn't take into account "Jr.", "Sr." or "III", etc. being after the last name, but it's better.

An additional thing to keep in mind is if your data isn't 100% clean and contains leading or trailing spaces, like "Jim R Green ", you'll need to use the TRIM command to clean it up. If you don't, it will throw off the count of spaces and give you a "#value!" error. Use this to ensure no leading or trailing spaces affect your results:

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

You can also alter the formula to include the comma between the last and first names, as in "Green, Jim R", by using this:

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

Hope that helps out some!


can you help me with this problem?

the original
14D-E13111-00
and i want it to be
E13111-14D-00

Thank you so very much...
2017-03-15 08:32 Reply Reply with quote Quote
Permalink 0 vivek
I want 20140115 to 15012014
2014-01-15 08:56 Reply Reply with quote Quote
Permalink 0 DiGi
The Macro worked for me. Thanks!
2014-01-25 07:13 Reply Reply with quote Quote
Permalink 0 Sciguy
Thanks - worked well and saved me a lot of time!
2014-09-25 16:15 Reply Reply with quote Quote
Permalink 0 Lea Carol Glennon
The first formula worked fine (once I got rid of the middle names). But now I want to alphabetize and it won't do it.......becaus e there's a formula in the cells?
2014-11-05 02:31 Reply Reply with quote Quote
Permalink 0 heyliddle
So there's a long, drawn out way that you can change the format of Lastname, Firstname Middle to Firstname Middlename Lastname.

Assume that Lastname, Firstname Middle is in Cell A1.

Highlight the cell/column that Lastname, Firstname Middlename(s) is in. Click Data tab->Text to Columns. Chose "Delimited" Next-> click all that apply in checklist and double click the line between Firstname and Secondname to remove it, Next-> Finish. Now Lastname is still in A1, and Firstname Middlename in B2.

In a new cell (let's say C1) use the forumla =Concatenate(B1 ," ",A1) and the name will now read as " Firstname Middlename Lastname" (note the space at the start).

I another cell (let's say D1) use =TRIM(C1) to remove the space.

And you're done! I'm sure there is a much easier process, but that's what works for me.

Cheers!
2014-11-19 22:37 Reply Reply with quote Quote
Permalink 0 Sureshkumar
Hello,

How to reverse the name in the format Lastname,Firstn ame to Firstname Lastname

Lets say Paul,John = John Paul
2015-06-26 12:25 Reply Reply with quote Quote
Permalink +1 Mike Gagne
Switching around the last, first is actually a little easier because we have that comma to help us. Assume that the name is in cell A1 and the formula used is:

TRIM(RIGHT(A1,L EN($A1)-FIND(", ",A1,1)))&" "&TRIM(LEFT(A1,FIND(",",A1,1)-1))

I put the TRIM command on both the first and last names to ensure that we are only going to have the single space between the two. Probably doesn't need the TRIM on the last name, but you never know if a space may be the first character of the cell or if there may be a space preceding the comma.
2015-06-30 20:53 Reply Reply with quote Quote
Permalink 0 Raj
I would like excel updates
2015-06-27 08:04 Reply Reply with quote Quote
Permalink 0 Dr. Demento
A suggestion - In an effort to encourage good programming practices (Option Explicit), please dim all variables.
2015-10-05 13:38 Reply Reply with quote Quote
Permalink 0 Jam Smith
Please help I need a formula to flip Alexa Victoria G. Garcia to Garcia, Alexa Victoria G.

Please help :) Thank you
2016-01-18 17:24 Reply Reply with quote Quote
Permalink 0 Mary
THANKS!!!!! This formula just saved me a bunch of time. I am sure I will use it again and again.
2016-06-11 17:41 Reply Reply with quote Quote
Permalink 0 Danny
If you have middle name how do you flip the last name? Example below.
Last name - first name - middle name
2017-01-09 14:09 Reply Reply with quote Quote
Permalink 0 Danny
Correction. What if i have four names? What's the formula?
Last name - first name - middle1 - middle2
2017-01-09 14:24 Reply Reply with quote Quote

Add comment


Security code
Refresh