Search Cell Against Range and Remove Any Matching Text

mdsurf

New Member
Joined
Aug 1, 2017
Messages
22
Office Version
  1. 2016
Platform
  1. MacOS
Hi! I'm trying to figure out how to remove text from a cell if it is present in a range. For example Let's say I have a cell that contains the following sentence.

John Smith left his home and went to the store on Saturday to buy groceries


Now let's say I also have a column with a list of values.

Range of Values
John Smith
Saturday
groceries
fishing
basketball

Is any of the text from the range of values (exact match) is present in the sentence, is there a way to remove it?

If set up properly the equation should return the value.

left his home and went to the store on to buy

In the answer above anything exactly matching the range of values has been removed. I know it's a bit of a weird example but trying my best to illustrate what I need to accomplish.

Thank you!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
When your range of Values is starting in D2.
If you want you can also have this as a Sub, changing the existing data

VBA Code:
Function jec(cell As String) As String
 Dim RXPattern
 RXPattern = Join(Application.Transpose(Range("D2", Range("D" & Rows.Count).End(xlUp))), "|")
 
 With CreateObject("VBScript.RegExp")
   .Global = True
   .Pattern = RXPattern
   jec = Application.trim(.Replace(cell, ""))
 End With
End Function

Excel Formula:
=jec(A1)


Map1
ABCD
1John Smith left his home and went to the store on Saturday to buy groceriesRange of Values
2left his home and went to the store on to buy John Smith
3Saturday
4groceries
5fishing
6basketball
KPI data dkdfdf
Cell Formulas
RangeFormula
A2A2=jec(A1)
 
Last edited:
Upvote 0
Hi JEC, thank you so much for the help here. Do you know if this is possible to do without VBA? I'm pretty newbish to excel and VBA is a bit over my head, wondering if there's an equation that can accomplish this as well.

Either way, thank you for your time and help.
 
Upvote 0
What version of Excel are you using & on what platform?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
In this case you need VBA..unfortunately there isn't a clean way to do this with formula's
 
Upvote 0
unfortunately there isn't a clean way to do this with formula's
That just depends on the OP's version of xl, but he/she doesn't seem to want to tell us.
 
Upvote 0
What if the list of values to replace is like 50 items long, how are you going to do that with a dynamic formula, all at once
 
Upvote 0
As I said, just depends on the version. But I'm not going to waste my time if the OP cannot be bothered to let us know what version they are using & I have asked for that info in two different threads.
 
Upvote 0
I am actually curious too
 
Upvote 0
One option

Map1
ABCD
1John Smith left his home and went to the store on Saturday to buy groceriesRange of Values
2left his home and went to the store on to buyJohn Smith
3Saturday
4groceries
5fishing
6basketball
Blad1
Cell Formulas
RangeFormula
A2A2=LET(x,FILTERXML("<x><y>"&SUBSTITUTE(A1," ","</y><y>")&"</y></x>","//y"),TEXTJOIN(" ",1,FILTER(x,ISERROR(MATCH(x,FILTERXML("<x><y>"&SUBSTITUTE(TEXTJOIN(" ",1,D2:D6)," ","</y><y>")&"</y></x>","//y"),0)),"")))
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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