firstName lastName to lastName, firstName in Excel spreadsheet

半腔热情 提交于 2020-08-26 13:44:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!