aristotleistimmy

New Member
Joined
Jan 18, 2012
Messages
12
How can I switch a cell of "first middle last" to "last, first" in excel?

the cells are different some have middle names and some don't. what is the general code.

such as switching from

thomas allen smith
adam wilson
amanda r smith

to

smith, thomas
wilson, adam
smith, amanda


thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255))&","& LEFT(A1,FIND(" ",A1)-1)
 

Muhamed Faizal

Board Regular
Joined
Aug 18, 2011
Messages
204
How can I switch a cell of "first middle last" to "last, first" in excel?

the cells are different some have middle names and some don't. what is the general code.

such as switching from

thomas allen smith
adam wilson
amanda r smith

to

smith, thomas
wilson, adam
smith, amanda


thanks

try the following
I'm using column C

=TRIM(RIGHT(SUBSTITUTE(C13," ",REPT(" ",LEN(C13))),LEN(C13)))&", "&TRIM(LEFT(SUBSTITUTE(C13," ",REPT(" ",LEN(C13))),LEN(C13)))
 

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,704
Office Version
  1. 2016
Platform
  1. Windows
How can I switch a cell of "first middle last" to "last, first" in excel?

the cells are different some have middle names and some don't. what is the general code.

such as switching from

thomas allen smith
adam wilson
amanda r smith

to

smith, thomas
wilson, adam
smith, amanda


thanks

Try this out

Excel Workbook
AB
1Full NameAs you Want them
2thomas allen smithsmith, thomas
3adam wilsonwilson, adam
4amanda r smithsmith, amanda
Sheet25
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,973
Office Version
  1. 2016
Platform
  1. Windows
How can I switch a cell of "first middle last" to "last, first" in excel?

the cells are different some have middle names and some don't. what is the general code.

such as switching from

thomas allen smith
adam wilson
amanda r smith

to

smith, thomas
wilson, adam
smith, amanda
You said "code", so here is a macro that will change the value within the cells themselves...

Code:
Sub LastCommaFirst()
  Dim X As Long, LastRow As Long, Parts() As String
  Const DataColumn As String = "A"
  Const StartRow As Long = 1
  LastRow = Cells(Rows.Count, DataColumn).End(xlUp).Row
  For X = StartRow To LastRow
    Parts = Split(WorksheetFunction.Trim(Cells(X, DataColumn).Value))
    Cells(X, DataColumn).Value = Parts(UBound(Parts)) & ", " & Parts(0)
  Next
End Sub
Just change the two constants (the Const statements) to reflect your actual setup.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,557
Messages
5,637,043
Members
416,955
Latest member
Gohar hussain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top