Name formatting in excel

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
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
Try

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

Muhamed Faizal

Board Regular
Joined
Aug 18, 2011
Messages
203
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,362
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
35,563
Office Version
2010
Platform
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.
 

Forum statistics

Threads
1,085,253
Messages
5,382,591
Members
401,796
Latest member
Ginger12

Some videos you may like

This Week's Hot Topics

Top