Finding last name problem

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
764
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
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
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
764
Office Version
  1. 2016
Platform
  1. Windows
A big thanks you

Thanks for your help. They work perfectly.
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
Here's an alternative, assuming your surname has no more than 99 letters

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

Forum statistics

Threads
1,136,267
Messages
5,674,729
Members
419,523
Latest member
Urnovio

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
Top