Excel formula to search within the string and count repetition

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
216
Office Version
  1. 2019
Platform
  1. Windows
I want an excel formula to identify the specific word "to" from a cell within the text multiple times, there is a space after the word "to". Please help me with the code.
to.PNG
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Here is the long version so you can see how it works (in case you want to search for other words)...

=(LEN(" "&A1&" ")-LEN(SUBSTITUTE(" "&A1&" "," to ","")))/LEN(" to ")

and here is the short version making use of information we know...

=(2+LEN(A1)-LEN(SUBSTITUTE(" "&A1&" "," to ","")))/4

Note: SUBSTITUTE is case sensitive, so if you want this to work even when the search word begins a sentence and thus starts with a capital letter, you would need to do this...

Long version...
=(LEN(" "&A1&" ")-LEN(SUBSTITUTE(" "&UPPER(A1)&" ",UPPER(" to "),"")))/LEN(" to ")

Short version...
=(2+LEN(A1)-LEN(SUBSTITUTE(" "&UPPER(A1)&" "," TO ","")))/4
 
Upvote 0
Solution
Here is the long version so you can see how it works (in case you want to search for other words)...

=(LEN(" "&A1&" ")-LEN(SUBSTITUTE(" "&A1&" "," to ","")))/LEN(" to ")

and here is the short version making use of information we know...

=(2+LEN(A1)-LEN(SUBSTITUTE(" "&A1&" "," to ","")))/4

Note: SUBSTITUTE is case sensitive, so if you want this to work even when the search word begins a sentence and thus starts with a capital letter, you would need to do this...

Long version...
=(LEN(" "&A1&" ")-LEN(SUBSTITUTE(" "&UPPER(A1)&" ",UPPER(" to "),"")))/LEN(" to ")

Short version...
=(2+LEN(A1)-LEN(SUBSTITUTE(" "&UPPER(A1)&" "," TO ","")))/4
Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,226,116
Messages
6,189,057
Members
453,523
Latest member
Don Quixote

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