You can quickly get the last name from a full name using the RIGHT, FIND, LEN, and SUBSTITUTE functions or an advanced Excel formula.
This post explains everything you need to know about the most important TEXT functions – or string manipulation functions, as it’s known. Then, if you are using custom user-defined functions (see the second part of the article), achieving your goal is possible.
Steps to get the last name from a name
Use the following steps to extract the first name in Excel:
- Open Excel
- Type =RIGHT(B3,LEN(B3)-FIND(“?”,SUBSTITUTE(B3,” “,”?”,LEN(B3)-LEN(SUBSTITUTE(B3,” “,””)))))
- The formula will extract the first name from cell B3.
Explanation
Let us see what you can do if you have a cell and want to get the last name from a full name. At first glance, we have to combine several functions — bad news. However, we will explain the method clearly and based on the previously mentioned generic formula example.
By default, in cell B3, we find the full text. The last name is separated from the other parts of the full text with a delimiter, in this case, space.
Place this below formula in cell D3:
=RIGHT(B3,LEN(B3)-FIND(“?”,SUBSTITUTE(B3,” “,”?”,LEN(B3)-LEN(SUBSTITUTE(B3,” “,””)))))
In summary, the RIGHT function gets the characters starting from the right side of the string. The inner section of the complex formula serves only one purpose: to calculate the number of characters that need to be extracted.
- The formula replaces the last space with a question mark “?”; you can use another asterisk like “*”. The FIND function gets the position of the question mark. The RIGHT function will use this parameter.
- In the formula above, an occurrence is calculated using the second SUBSTITUTE.
- We’ll get the string length in cell B3 using the LEN function.
- We have two spaces in the full name, so we get =10 – 8 = 2
- Use this value as in the occurrence number: =SUBSTITUTE(B3,”, “”?”,2), which replaces the second space with “?”
- The name then looks like this: “John W?Do”. The FIND function then takes over to figure out where the “?” is in the name.
- The result is 7 because the “?” is in the 7th position, subtracted from the total length of the text string: =LEN(B3)-7
- The RIGHT function uses the 3 as an argument, so we’ll get the final result: =RIGHT(B3,3) = “Doe”
Extract the last name using the GETWORDS function
It’s not necessary to go at this paper hammer and tongs. We want to save time and use the fastest method. Check our free Excel add-in! DataFX – our advanced UDF library – provides unique functions for Excel. We continuously integrate the latest string manipulation functions.
In the example, use the formula below:
=GETWORDS(B3, 3, ” “)
The substring function gets the nth element of a text string. The elements are separated by a specified separator character (delimiter) to save time.
Related Formulas and Examples
- Extract the first name from a full name
- Get the middle name from the full name
- Join first and last name