Home » excel » extract names in excel

# extract names in excel

Questions:

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?

``````=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.

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))
``````  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")`

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

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

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.