问题
I am trying to get an excel spreadsheet that has the names Jane Doe and John Smith, go from that to Doe, Jane, and Smith, John.
I can only find ways to go from lastName, firstName to firstName lastName, but none for the contrary.
Thank you.
回答1:
For formulas use:
=MID(A1,FIND(" ",A1)+1,999) & ", " & LEFT(A1,FIND(" ",A1)-1)
Now to the next question: What if there are more than just the first and last name?
Use this:
=MID(A1,FIND("}}}",SUBSTITUTE(A1," ","}}}",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))+1,999) & ", " & LEFT(A1,FIND("}}}",SUBSTITUTE(A1," ","}}}",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))-1)
It will assume the last word is the last name.
回答2:
Select only the cells you wish to convert and run this small macro:
Sub NameFixer()
For Each r In Selection
ary = Split(r.Value, " ")
r.Value = ary(1) & ", " & ary(0)
Next r
End Sub
回答3:
Alternate formula solution:
=LEFT(TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99))&", "&A1,LEN(A1)+1)
来源:https://stackoverflow.com/questions/35092908/firstname-lastname-to-lastname-firstname-in-excel-spreadsheet