extract names in excel

帅比萌擦擦* 提交于 2019-12-08 04:59:01

问题


In my excel file column G I have names with last name + first name + middle name. For example Tasha, William P is the sample name and Tasha is the Last name, William is the first name and P would be the middle name. I was able to pull last name by =LEFT(G2, FIND(",", G2)-1), but can't tell what would be the good ways to extract middle and first name. How can extract first and middle name with excel formula?


回答1:


=RIGHT(G2,1)

for the middle initial.

=LEFT(G2,(FIND(",",G2,1)-1))

for the first name.

=TRIM(MID(SUBSTITUTE(G2, " ", REPT(" ", 99)),2 * 99 - 98,99))

for the last name.




回答2:


You can use this one formula:

=TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1,",","")," ",REPT(" ",999)),(COLUMN(A:A)-1)*999+1,999))

Put it in B1 and copy over 3 columns and down the length of the data.


If you want to put them in order then use this:

=TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1,",","")," ",REPT(" ",999)),(CHOOSE(COLUMN(A:A),1,2,0))*999+1,999))




回答3:


Method 1 Using LEFT+RIGHT+MID+FIND functions

First Name: =MID(A2,FIND(",",A2)+2,FIND(" ",A2,FIND(" ",A2)+1)-FIND(",",A2)-2)

Middle Name: =RIGHT(A2,LEN(A2)-FIND(" ",A2,FIND(" ",A2)+1))

Last Name: =LEFT(A2,FIND(",",A2)-1) same as yours

The logic to find First Name is to find the position of ,(space) and the second (space) and return the characters in between. The logic for Middle Name is to find the second (space) and return whatever is on the right.

Method 2 Using FILTERXML+SUBSTITUTE functions

First Name: =FILTERXML("<data><a>"&SUBSTITUTE(SUBSTITUTE(A7,",","")," ","</a><a>")&"</a></data>","/data/a[2]")

Middle Name: =FILTERXML("<data><a>"&SUBSTITUTE(SUBSTITUTE(A7,",","")," ","</a><a>")&"</a></data>","/data/a[3]")

Last Name: =FILTERXML("<data><a>"&SUBSTITUTE(SUBSTITUTE(A7,",","")," ","</a><a>")&"</a></data>","/data/a[1]")

The logic is to use SUBSTITUTE to convert the full name into something like the following:

<data><a>Last Name</a><a>First Name</a><a>Middle Name</a></data>

Then use FILTERXML to return the desired name based on its order 1, 2 or 3 within the XML script.

For the logic behind this formula you may give a read to this article: Extract Words with FILTERXML.



来源:https://stackoverflow.com/questions/57929340/extract-names-in-excel

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