SUBSTITUTE function with a range of values to substitute

RonOliver

Board Regular
Joined
Aug 30, 2022
Messages
82
Office Version
  1. 365
Platform
  1. Windows
Hi, everyone,

I have been working on a formula that splits full names into names and surnames, but I have a problem. Let me tell you what it is:

Avaluació 2022-23 PROVES.xlsx
CDEF
4Jorge Guzmán PedrazaJorgeGuzmánPedraza
5David Tejero GarcíaDavidTejeroGarcía
6Tamara Bas MorenoTamaraBasMoreno
7Miguel Ureña PérezMiguelUreñaPérez
8Mónica Estadellas VacaMónicaEstadellasVaca
9Lena Viejo AlegreLenaViejoAlegre
10Francesco SchettinoFrancescoSchettino
11Marta Arenas CabrerizoMartaArenasCabrerizo
12Aura López AlcázarAuraLópezAlcázar
13Javier Alarcón AznarJavierAlarcónAznar
14Nabil HrairaNabilHraira
15Javier Fernández ParraJavierFernándezParra
16Fátima Andrade BayarriFátimaAndradeBayarri
17Noemi Caravantes FenollosaNoemiCaravantesFenollosa
18Gabriela López-Moreno del PinoGabrielaLópez-Morenodel Pino
19Carlos de la Torre RamírezCarlosde-la TorreRamírez
20Juan Antonio García GarcíaJuan AntonioGarcíaGarcía
21María de los Ángeles de Ojeda del PinoMaría de-los Ángelesde Ojedadel Pino
Separadora
Cell Formulas
RangeFormula
D15:F21,D14:E14,D11:F13,D10:E10,D4:F9D4=LET(t,TRIM(C4),nm,IF(ISNUMBER(FIND(",",t)),MID(t&" "&t,FIND(",",t)+2,LEN(t)-1),t),arr,SUBSTITUTE(TEXTSPLIT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(nm," y "," y#")," Y "," Y#")," i "," i#")," I "," I#")," dels "," dels#")," Dels "," Dels#")," de les "," de-les")," De les "," De-les")," els "," els#")," Els "," Els#")," les ","les#")," Les "," Les#")," De La "," De-La#")," De Las "," De-Las#")," De Los "," De-Los#")," Del "," Del#")," De "," De#")," El "," El#")," La "," La#")," Los "," Los#")," Las "," Las#")," de la "," de-la#")," de las "," de-las#")," de los "," de-los#")," de "," de#")," del "," del#")," el "," el#")," la "," la#")," los "," los#")," las "," las#")," "),"#"," "),last,TAKE(arr,,-2),first,TEXTJOIN(" ",1,DROP(arr,,-2)),IF(nm="","",IF(LEN(nm)-LEN(SUBSTITUTE(nm," ",""))+1=2,HSTACK(last),HSTACK(first,last))))
Dynamic array formulas.


The thing is some languages (like Spanish and German) have prepositions and articles that go with last names. The formula that I'm using correctly identifies the prepositions and takes them with their corresponding last name. However, as the list of prepositions to substitute increases in size, the formula gets clunkier and clunkier. I'd like to use a helper column where I can get all possible variations of prepositions and articles, so that the formula can do the same thing the current formula is doing without having to copy the full list of prepositions on every single cell (pretty muchthe way it works on the formula, but on a column, which would definitely shrink the formula substantially). I've tried using a range in the substitute function, but I couldn't get it to work. What can I do? Thanks for your help!
 
That's weird. I added "van" to the preposition list and it gave me a #CALC! error,
No, it isn't weird because you didn't say in post #7 that you had added anything to the prepositions list, so I didn't either. ;)
In any case I assume you added "von" not "van". Or else you typed the wrong sample name in post #7.
I do get the error if I add "von" to the list. :)

but that's fixed now, anyway.
(y)
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

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