Extracting First And Last Names
A frequent task many people encounter when working with lists of data in Excel is splitting full names into the first-name and last name components. For example, a user may have full names like "Pearson, Charles H" in column A, and needs to put the last name in column B, the first name in column C, and the middle initial in column D. This page describes some worksheet formulas and VBA procedures you can use to accomplish this. For a related procedure for working with telephone numbers, see Parsing Telephone Numbers. All of the functions and procedures on this page assume that your data is formatted as "LastName, FirstName MiddleName". For example, "Pearson, Charles H". Suffixes like "Jr" are permitted in the LastName, as are two word last names (e.g., St James) and hyphenated last names (e.g., Smith-Cross). For example, all the the following names are valid. Pearson
This section describes several worksheet functions you can use to split full names into the first and last name components. To return the last name of the full name in A2, use the following formula. =LEFT(A2,IF(ISERROR(FIND(",",A2,1)),LEN(A2),FIND(",",A2,1)-1)) To return the first name of the full name in A2, use the following formula. =TRIM(IF(ISERROR(FIND(",",A2,1)),A2,MID(A2,FIND(",",A2,1)+1, To return the middle name of the full name in A2, use the following formula. =TRIM(RIGHT(A2,LEN(A2)-IF(ISERROR(FIND(" ",A2, The results of these formulas are shown below:
|
||
|
||
This section describes a VBA function you can use the split full names into the the first and last name components. This procedure accepts a full name, as described above, and returns an array for four elements -- the Last Name, the First Name, the Middle Initial, and the Suffix. Therefore, you will need to enter this as an Array Formula. Suppose you want the four parts of the name in A2 to be returned to B2:E2. First, select cells B2:E2, enter =ParseOutNames(A2) and press Ctrl+Shift+Enter rather than just Enter. The code recognizes the following suffixes: JR, SR, II, III, IV The code will also convert all names to Proper Case.
The result of this formula are shown below:
|
|
|
For a related procedure for working with telephone numbers, see Parsing Telephone Numbers. |
||