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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255))&","& LEFT(A1,FIND(" ",A1)-1)
 
Upvote 0
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)))
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,514
Messages
6,114,078
Members
448,547
Latest member
arndtea

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
Back
Top