Substitute string in cell if one of many

Okoth

Board Regular
Joined
Sep 10, 2009
Messages
106
Office Version
  1. 2019
Platform
  1. Windows
I am totally stuck with this. I have tried helper cells, substitute and sumif formulas but I cannot get what I want.

So, I have a list with values. There is a text and if a word in the text matches a word in the list then it has to be replaced with a word that is in a cell next to the cell in the list.

An example

[TABLE="class: grid, width: 600, align: left"]
<tbody>[TR]
[TD]TEXT[/TD]
[TD]LIST[/TD]
[TD]becomes[/TD]
[TD]THIS[/TD]
[/TR]
[TR]
[TD]The white cat will be replaced by a black fish[/TD]
[TD]duck[/TD]
[TD]becomes[/TD]
[TD]mouse[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]cat[/TD]
[TD]becomes[/TD]
[TD]fish[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]dog[/TD]
[TD]becomes[/TD]
[TD]bird[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]sheep[/TD]
[TD]becomes[/TD]
[TD]rat[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]monkey[/TD]
[TD]becomes[/TD]
[TD]owl[/TD]
[/TR]
[TR]
[TD]Result:[/TD]
[TD]worm[/TD]
[TD]becomes[/TD]
[TD]eagle[/TD]
[/TR]
[TR]
[TD]The white fish will be replaced by a black fish[/TD]
[TD]goose[/TD]
[TD]becomes[/TD]
[TD]mole[/TD]
[/TR]
</tbody>[/TABLE]

How can I do this?
 
Last edited:
Hi,

I have a much simpler solution if you're still interested.

Yes, please. I still might have problems with the code above with the data I have, but still testing...
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,

I have a much simpler solution if you're still interested.

Yes, please. I still might have problems with the code above with the data I have, but still testing...

This will work for any number of words for Column B to be replaced/substituted in the subject text string in A1 by corresponding word(s) in Column D:


Book1
ABCD
1The bald polar bear cub will be replaced by a black fishduckbecomesmouse
2catbecomesfish
3hairy dogbecomesbird
4sheepbecomesrat
5monkeybecomesowl
6Result:wormbecomeseagle
7The giant brown bear will be replaced by a black fishbald polar bear cubbecomesgiant brown bear
8The giant brown bear will be replaced by a black fish
Sheet120
Cell Formulas
RangeFormula
A7=SUBSTITUTE(A1,LOOKUP(2,1/FIND($B$1:$B$7,A1),$B$1:B$7),LOOKUP(2,1/FIND($B$1:$B$7,A1),$D$1:$D$7))
A8=SUBSTITUTE(A1,LOOKUP(2,1/SEARCH($B$1:$B$7,A1),$B$1:B$7),LOOKUP(2,1/SEARCH($B$1:$B$7,A1),$D$1:$D$7))


A7 formula case sensitive.
A8 formula Not case sensitive.
 
Last edited:
Upvote 0
Hi,

I tried the A8 formula and it gave me immediately what I wanted. Thanks.
 
Upvote 0
You're welcome, happy it works for you.

Edit: Also, your Column B and D range can be as long as you need, just adjust the ranges in the formula to suit.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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