Extract prepositions next to last names only if the name is the last word in a string

RonOliver

Board Regular
Joined
Aug 30, 2022
Messages
99
Office Version
  1. 365
Platform
  1. Windows
Hi, everyone. Need some help with a stumper.

I'm trying to create a tool that splits the name and last name in a cell into three cells (one cell for the first name and the other two for both last names, as we have two last names in Spanish). The rest of the formula is already put together correctly. Here's the problem. It's gonna be a wild ride, so bear with me, please.

The main problem here is some last names in Spanish have prepositions next to them (such as "de la Torre" or "del Pino"). I tried to create a formula that either takes the last name OR it takes all the text at the right of the cell starting from the preposition. This is the formula that I wrote:

Excel Formula:
=IFERROR(RIGHT(C19;LEN(C19)-FIND(" de la ";C19));TEXTAFTER(C19;" ";-1))

This formula works well if the full name is "Carlos Fernández de la Torre" (it returns "de la Torre"), but not if the name is "Jorge de la Torre Fernández" (it returns "de la Torre Fernández"). I need a formula that is able to return the last name (including "de la") ONLY if the word to the right of "de la" is the last word in the string of text. The desired result if C19 was "Jorge de la Torre Fernández" is "Fernández". However, if C19 was "Carlos Fernández de la Torre", the desired result would in turn be "de la Torre". I know the problem is a bit convoluted, but I appreciate all the help I get.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
One way.
Test.xlsm
AB
1NameLast Name
2Carlos Fernández de la Torrede la Torre
3Jorge de la Torre FernándezFernández
4Sylvia Gutierrez VelardeVelarde
Sheet13
Cell Formulas
RangeFormula
B2:B4B2=LET(Name,A2,TmpStr, TRIM(RIGHT(SUBSTITUTE(Name," ",REPT(" ",100)),50)),IF(MID(Name,LEN(Name)-LEN(TmpStr)-5,5)="de la","de la " & TmpStr,TmpStr))
 
Upvote 0
Solution
Thanks so very much. I have never used LET, so I don't know what "Name" and "TmpStr" are placeholders of. I tried to paste it straight to my file replacing the cells, but I can't get it to work. Could you help me some more?
 
Upvote 0
First try pasting my example to a new worksheet.
1668287948223.png


Then you must explain any problem in detail. Phrases like "it does not work" are too vague.


The free XL2BB tool (link below) is available to post your data in a way that makes it accessible to others.

 
Upvote 0
I'm sorry. I used Excel in a different language on a computer I don't own. Thanks so much!!
 
Upvote 0

Forum statistics

Threads
1,224,835
Messages
6,181,245
Members
453,026
Latest member
cknader

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