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 smith
3adam wilson
4amanda r smith
Sheet25
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,504
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,081,770
Messages
5,361,173
Members
400,617
Latest member
barron1

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top