Count words in a cell except some specific words

RonOliver

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

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, but I got stumped trying to do something.

I tried to write a formula that counts how many words there are in a cell (by counting spaces and then adding one). The formula looks like this:
Excel Formula:
=LEN(TRIM(C18))-LEN(SUBSTITUTE(C18," ",""))+1

The problem is that I want a formula that counts words in a cell EXCEPT certain words. For example, it's common for some last names to include prepositions (like "de Castro"). I do not want to count those as two words, but as one. Could you please help me with this? Thanks!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
try this:
Excel Formula:
=LEN(TRIM(C18))-LEN(SUBSTITUTE(C18," ",""))+1-(1*(FIND(" de ",C18)>0))
add another "find" for each conmbination you want to exclude
 
Upvote 0
Solution
Assuming you have a list of propositions from Z2 to Z20 like del, dos, les, los... Use your original formula and subtract this
Excel Formula:
yourOriginalFormula-SUMPRODUCT(ISNUMBER(SEARCH($Z$2:$Z$20,$A2))+0)
 
Upvote 0
Assuming you have a list of propositions from Z2 to Z20 like del, dos, les, los... Use your original formula and subtract this
Excel Formula:
yourOriginalFormula-SUMPRODUCT(ISNUMBER(SEARCH($Z$2:$Z$20,$A2))+0)
Looks great! I'll try and see if I can get my own formula shorter by adding this. :)
 
Upvote 0
Like
Excel Formula:
=LEN(TRIM(C18))-LEN(SUBSTITUTE(C18," ",""))+1-SUMPRODUCT(ISNUMBER(SEARCH($Z$2:$Z$20,C18))+0)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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