How to find certain words contained in cell

mljohn

Board Regular
Joined
Aug 26, 2004
Messages
196
Office Version
  1. 365
Platform
  1. Windows
I have a cell that contains a description of a product. (H2)
In that description sometimes there are the words "Black", "Cyan", "Magenta" or "Yellow". If the H2 cell contains one of these words I want to have the I2 cell show the word that was found.

(H2) "Yellow baseball cap" = (I2) Yellow

What is the formula for this?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try:

=LOOKUP(9.99999999999999E+307,SEARCH({"Black","Cyan","Magenta","Yellow"},H2),{"Black","Cyan","Magenta","Yellow"})

In I2.

Matty
 
Upvote 0
I have a cell that contains a description of a product. (H2)
In that description sometimes there are the words "Black", "Cyan", "Magenta" or "Yellow". If the H2 cell contains one of these words I want to have the I2 cell show the word that was found.

(H2) "Yellow baseball cap" = (I2) Yellow

What is the formula for this?
If the word may appear anywhere within the cell...

=LOOKUP(1E100,SEARCH({"Black";"Cyan";"Magenta";"Yellow"},H2),{"Black";"Cyan";"Magenta";"Yellow"})
 
Upvote 0
Great.

Two questions:
1. If the cell does not contain any of those words how do I leave the result blank?

2. In the formula what does the 1E100 (1E+100) mean?
 
Upvote 0
Great.

Two questions:
1. If the cell does not contain any of those words how do I leave the result blank?
Try one of these...

If you're using Excel 2007 or later:

=IFERROR(LOOKUP(1E100,SEARCH({"Black";"Cyan";"Magenta";"Yellow"},H2),{"Black";"Cyan";"Magenta";"Yellow"}),"")

This one will work in any version of Excel:

=LOOKUP("zzzzz",CHOOSE({1,2},"",LOOKUP(1E100,SEARCH({"Black";"Cyan";"Magenta";"Yellow"},H2),{"Black";"Cyan";"Magenta";"Yellow"})))

2. In the formula what does the 1E100 (1E+100) mean?
1E100 is scientific notation for a very large number, 1 followed by 100 zeros.

In this application the SEARCH function will return the starting position of the lookup word within the cell (if found).

Since a cell can contain a maximum of 32,767 characters, the largest value that the SEARCH function can return is 32,767.

So, we need a lookup value that is greater than 32,767. We could use 32,768 but 1E100 is nice and compact and easy to remember.
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,572
Members
452,927
Latest member
whitfieldcraig

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