ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Text "comparison" operator for "contains" used in an "IF" Function (https://www.excelbanter.com/excel-worksheet-functions/66171-text-comparison-operator-contains-used-if-function.html)

Pawaso

Text "comparison" operator for "contains" used in an "IF" Function
 
I'm trying to use an "IF" function to look for a certain word in a string of
text. Is there a "contains" operator for this?

I tried using =if(A1="*example*","yes","no") but this does not seem to work.

ExcelBanter AI

Answer: Text "comparison" operator for "contains" used in an "IF" Function
 
Yes, there is a "contains" operator that you can use in an "IF" function to look for a certain word in a string of text. The operator you can use is the asterisk (*) symbol, which is a wildcard character that represents any number of characters.

To use the "contains" operator in an "IF" function, you can modify your formula to the following:
  1. Formula:

    =IF(ISNUMBER(SEARCH("example",A1)),"yes","no"


In this formula, the SEARCH function is used to look for the word "example" in cell A1. If the word is found, the function returns the position of the first character of the word in the text string. If the word is not found, the function returns the #VALUE! error.

The ISNUMBER function is then used to check if the result of the SEARCH function is a number (i.e. the word was found). If the result is a number, the function returns TRUE. If the result is an error, the function returns FALSE.

Finally, the IF function is used to return "yes" if the word was found (i.e. the result of the ISNUMBER function is TRUE), and "no" if the word was not found (i.e. the result of the ISNUMBER function is FALSE).

Niek Otten

Text "comparison" operator for "contains" used in an "IF" Function
 
You can use the FIND function and test for a (non-) error result (ISERROR)

--
Kind regards,

Niek Otten

"Pawaso" wrote in message
...
I'm trying to use an "IF" function to look for a certain word in a string
of
text. Is there a "contains" operator for this?

I tried using =if(A1="*example*","yes","no") but this does not seem to
work.




Elkar

Text "comparison" operator for "contains" used in an "IF" Function
 
Try this:

=IF(ISERROR(FIND("example",A1,1)),"no","yes")

HTH,
Elkar

"Pawaso" wrote:

I'm trying to use an "IF" function to look for a certain word in a string of
text. Is there a "contains" operator for this?

I tried using =if(A1="*example*","yes","no") but this does not seem to work.


Dave Peterson

Text "comparison" operator for "contains" used in an "IF" Function
 
=find() is case sensitive
=search() doesn't care about case (Example/EXAMPLE/ExAmPlE will be treated the
same)

another way:

=if(countif(a1,"*example*")0,"yep","nope")

(not case sensitive)

Pawaso wrote:

I'm trying to use an "IF" function to look for a certain word in a string of
text. Is there a "contains" operator for this?

I tried using =if(A1="*example*","yes","no") but this does not seem to work.


--

Dave Peterson


All times are GMT +1. The time now is 04:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com