Counting text within a text string

Ride The Lightning

Board Regular
Joined
Jul 14, 2005
Messages
238
Hi

I have a concantated column of text strings. I want to be able to search within the text strings in the column and highlight (in colour if possible) particular letters that occur when I imput those letters in the cell the formula will relate to.

For example, I have in A3 "InthebeginningGodcreatedtheheavenandtheearth"
In cell A4 "Andtheearthwaswithoutformandvoidanddarknesswasuponthefaceofthedeep.AndtheSpiritofGodmoveduponthefaceofthewaters."

Cell A1 would be formula cell and cell B1 would have the imput criteria. If the imput criteria was "th" then it should highlight each time these two adjacent characters appear.

I have tried the Search function, but it only returns the reference of the 1st appearance of the characters.

Would appreciate help.

Thanks

RTL
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You could count using the SUBSTITUTE function

Code:
=IF(B1="","",(LEN(A3)-LEN(SUBSTITUTE(A3,B1,"")))/LEN(B1))

I don't think you could highlight part of the text with just a formula. You would need a VBA solution.
 
Upvote 0
Try something like this...

Code:
=IF(B1="","",SUMPRODUCT((LEN([COLOR="Red"]A3:A10[/COLOR])-LEN(SUBSTITUTE([COLOR="Red"]A3:A10[/COLOR],B1,"")))/LEN(B1)))
 
Upvote 0
Try something like this...

=IF(B1="","",SUMPRODUCT(((LEN(A3:A10)-LEN(SUBSTITUTE(A3:A10,B1,"")))/LEN(B1))))
Since SUBSTITUTE is case sensitive it might be a good idea to ensure everything is the same case.

=SUMPRODUCT(LEN(A3:A10)-LEN(SUBSTITUTE(UPPER(A3:A10),UPPER(B1),"")))/LEN(B1)
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

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