Extracting last name from full name

bearcub

Well-known Member
Joined
May 18, 2005
Messages
702
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I have to extract the last name and join it with elements to create a position title that is used in an application.

This is the formula:

TRIM(E10&"-"&F10&"-"&UPPER(RIGHT(A10,SEARCH(" ",A10))))&"-"&G10

The issue I am having with is in the Upper(Right) section that extracts the last name from the name.

The formula works okay until I have people a middle name, etc. The formula works well only if their are 2 works. The formula goes wonky when I have a 1st, middle & last name.

Is there a formula that will find the last space in the name and extract the last name? Note row 10, this person has 4 names instead of 2. And the result is including the 2nd, 3rd & 4th words of the name.

This is the source data and results (Column C)

Cell Formulas
RangeFormula
C11=TRIM(E11&"-"&F11&"-"&UPPER(RIGHT(A11,SEARCH(" ",A11))))&"-"&G11
Press CTRL+SHIFT+ENTER to enter array formulas.
XD]C11[/XD]
 
I see you have ms365, so try the below:

Excel Formula:
=TEXTAFTER(A2," ",-1)
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Yes, your formula works great as well. I get a little confused when I see the substitute function since I don't use it much. So, internally you're adding 100 spaces before Torres which in a way makes it dynamic in conjunction with the Trim function. Really cool, I like it! I always am interested in seeing different formulas for solving the same issue.

could you walk me through what the Find portion of the formula is doing?

RIGHT(A3,LEN(A3)-FIND("*",SUBSTITUTE(A3," ","*",LEN(A3)-LEN(SUBSTITUTE(A3," ",""))).

It looks like the find is returning the entire name minus the space?
 
Upvote 0
Thank you. Does Flash fill join different columns?
Flash fill is not a formula, you just start capturing the data in the right column, excel recognizes the pattern and performs it on all the data.
You can use this column and then concatenate this column with the other columns you already have.

 
Upvote 0
Yes, your formula works great as well. I get a little confused when I see the substitute function since I don't use it much. So, internally you're adding 100 spaces before Torres which in a way makes it dynamic in conjunction with the Trim function. Really cool, I like it! I always am interested in seeing different formulas for solving the same issue.

could you walk me through what the Find portion of the formula is doing?

RIGHT(A3,LEN(A3)-FIND("*",SUBSTITUTE(A3," ","*",LEN(A3)-LEN(SUBSTITUTE(A3," ",""))).

It looks like the find is returning the entire name minus the space?
I could walk you through the formula, but I'm going to suggest you check out the explanation helpfully provided by Dave Bruns instead: Excel formula: Get last name from name | Exceljet :p

I would add that JvdV's suggestion above is quite elegant - it's only currently available on MS365 (as far as I know), so if you send a workbook with a formula containing TEXTAFTER to someone without MS365, your day will almost certainly end with tears and screaming and recriminations and a series of blood feuds getting started ... I speak from experience... LOL

That said, honestly, I'd be minded to remake the TEXTAFTER function in VBA, but VBA is usually an issue for some people... Just a thought.
 
Upvote 0
Thank you. I"ll check out Dave's site, I'm familiar with it. I just read the explanation and I understand what is happening.

In regards to Dante's flash fill explanation, it does look like I would have to have another formula in another column which is workable as well. Thank you Dante.
 
Upvote 0
Power Query solution:

1666908023038.png
 
Upvote 0
Thank you for the Power Query solution. I didn't think about that.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top