user3110571
user3110571

Reputation: 23

Excel: matching the content of cell A on cell B and replacing the text

My problem is the following:

I have two cells (A & B) in a excel spreadsheet. I need to find in cell A the word(s) contained in cell B; I need then to copy the entire content of cell A in a new cell and replacing the word found with the exact content of cell B plus a tag.

Example.

Cell A: "bla bla bla word bla bla bla"

Cell B: "word"

Expected result:

Cell C: "bla bla bla [tag]word[/tag] bla bla bla"

At the moment I have been able to find the text contained of cell B in cell A, and to copy the entire text to a new cell if the text if found, othewise it writes "not ok":

=IF(ISNUMBER(FIND(B2; A2)); A2; "Not OK")

I hope my question is clear enough. Thanks to everyone who will have the time and patience to help me! Alex

Upvotes: 2

Views: 704

Answers (2)

Michael
Michael

Reputation: 538

Is this what you're trying to do?

=IF(ISNUMBER(FIND(B2, A2)), REPLACE(A2,FIND(B2, A2),LEN(B2),"[tag]" & B2 & "[/tag]"), "Not OK")

This results in:

bla bla bla [tag]word[/tag] bla bla bla

Upvotes: 0

Sam
Sam

Reputation: 7303

I think that you should be able to just use Substitute?

=SUBSTITUTE(A1,B1,"[Tag]"&B1&"[/Tag]")

Upvotes: 3

Related Questions