Finding last name problem

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
778
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to amend this formula to find the last name in a cell that has the a fist name and second name, as copied from cpearson, a big thank you too him :

=TRIM(RIGHT(K239,LEN(K239)-IF(ISERROR(FIND(" ",K239,FIND(" ",K239,FIND(" ",K239,1)+2))),LEN(K239),FIND(" ",K239,FIND(" ",K239,FIND(" ",K239,1)+2))-1)))

I have already amended it to look for spaces rather than "," seperators. But it will only work when there is a middle name. Is it possible to change it to find the last name only?

Any help would be much appreciated.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi hatstand

Assuming the last name comes after a space, this formula will extract it no matter how many names the person has:

Code:
=RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1," ","#",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))


Hope this helps
PGC
 
Upvote 0
If A1 contains John Smith or John Peter Smith (or even Mr John Perter Smith) this:

=RIGHT(A1,LEN(A1)-FIND("@",SUBSTITUTE(A1," ","@",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

will return Smith.
 
Upvote 0
A big thanks you

Thanks for your help. They work perfectly.
 
Upvote 0
Here's an alternative, assuming your surname has no more than 99 letters

=TRIM(RIGHT(SUBSTITUTE(TRIM(A1)," ",REPT(" ",99)),99))
 
Upvote 0

Forum statistics

Threads
1,214,540
Messages
6,120,107
Members
448,945
Latest member
Vmanchoppy

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