Search partial text strings in range and replace with range

hashbrown91

New Member
Joined
Aug 23, 2017
Messages
3
Hi everyone,

I wanted to check if someone knows a way of simplifying a data cleaning process I do often. Suppose below is the data I have to clean:

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Data To Clean[/TD]
[TD]Term to Search[/TD]
[TD]Term To Replace with[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Essential Blue[/TD]
[TD]Blue[/TD]
[TD]Blue[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Deep Purple[/TD]
[TD]Purple[/TD]
[TD]Purple[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Bright Yellow[/TD]
[TD]Yellow[/TD]
[TD]Yellow[/TD]
[/TR]
</tbody>[/TABLE]

So far here is the formula I have been using:

=IF(ISNUMBER(SEARCH("Blue",A2)),"Blue",IF(ISNUMBER(SEARCH("Purple",A2)),"Purple",IF(ISNUMBER(SEARCH("Yellow",A2)),"Yellow","No Match") and then I just drag the formula down.

This does the job, but as you can tell it's a very manual process especially with large data sets since all conditions have to be entered individually so there is also a lot of room for error. What I wanted to know is if it is possible to search the entire Range of Column B in Column A, and then replace with the relevant term in Column C? I have tried using ranges in this current formula but it doesn't seem to work.

Any help would be appreciated! Cheers!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi, welcome to the forum!

Something like this maybe:


Excel 2013/2016
ABCDE
1Data To CleanTerm to SearchTerm To Replace with
2Essential BlueBlueBlueBlue
3Deep PurplePurplePurplePurple
4Bright YellowYellowYellowYellow
5Essential BlueRedSomethingBlue
6blueberryBlue
7Text Purple TextPurple
8Text Red TextSomething
9text text textNo Match
Sheet1
Cell Formulas
RangeFormula
E2=IFERROR(LOOKUP(1,-SEARCH($B$2:$B$5,A2),$C$2:$C$5),"No Match")
 
Upvote 0
Thank you!

The solution works! Amazing! I had a follow up question though :) Suppose in A9 there is "blue purple text text text". Both Blue and Purple are in Column B so from my testing the result that will come in E9 will be Blue, since it is the first term in A9 (if Purple was first then Purple would come). Any way to not match the first term that comes in A9 but instead prioritize whichever term in the whole string matches first in Column E? (I hope this makes sense!)
 
Upvote 0
Any way to not match the first term that comes in A9 but instead prioritize whichever term in the whole string matches first in Column E?

Hi, the formula as written will return the last found match that is listed in the "Term to Search" column - is this something you can work with to set your priorities?
 
Upvote 0
Ah okay, makes sense. Yes I can arrange the "Terms to Search" in a way that works correctly. I was just curious to know if there was a way to expand the formula to account for double matches and give an entirely different result or choose which of the 2 matches would display. Really appreciate the help and knowledge!
 
Upvote 0
Glad you can get it working the way you want :)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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