• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

If text is within a string then return a certain number...not working

Warren Keogh

New Member
Hi

I have a sample file attached. I want to a cell containing text. If the text is there then it returns an account code number, (there could be multiple searches). This is the formula I have used and it only works for the first text search ("CAR") what am I doing wrong??

=IF(SEARCH("*"&"CAR"&"*",A2),208,IF(SEARCH("*"&"BIKE"&"*",A2),206))

Thanks

WK
 

Attachments

  • sample.xlsx
    9.2 KB · Views: 7
@Warren Keogh,

When the search function does not find the specified text, it produces an error and not a true/false. To correct your formula, you simply need to handle the error. You may try either of the options below.

=IF(IFERROR(SEARCH("*"&"CAR"&"*",A2),),208,IF(IFERROR(SEARCH("*"&"BIKE"&"*",A2),),206))

or

=IF(NOT(ISERROR(SEARCH("*"&"CAR"&"*",A2))),208,IF(NOT(ISERROR(SEARCH("*"&"BIKE"&"*",A2))),206))

Hope that helps.

Regards,
Ken
 
Here is another way
=IF(ISNUMBER(FIND("CAR",$A$2:$A$8)),208,IF(ISNUMBER(FIND("BIKE",RNG)),206,""))
 
Here is another way
=IF(ISNUMBER(FIND("CAR",$A$2:$A$8)),208,IF(ISNUMBER(FIND("BIKE",RNG)),206,""))

if you need more things to check for you can add to this formula and probably the above ones as well ... but be careful that you dont have something to check for that contains two of the criteria eg CAR HIT BIKE as it will only pick the first match
 

Attachments

  • sample.xlsx
    10 KB · Views: 3
Last edited:
@Warren Keogh,

When the search function does not find the specified text, it produces an error and not a true/false. To correct your formula, you simply need to handle the error. You may try either of the options below.

=IF(IFERROR(SEARCH("*"&"CAR"&"*",A2),),208,IF(IFERROR(SEARCH("*"&"BIKE"&"*",A2),),206))

or

=IF(NOT(ISERROR(SEARCH("*"&"CAR"&"*",A2))),208,IF(NOT(ISERROR(SEARCH("*"&"BIKE"&"*",A2))),206))

Hope that helps.

Regards,
Ken
Thanks Ken very useful.
 
Here is another way
=IF(ISNUMBER(FIND("CAR",$A$2:$A$8)),208,IF(ISNUMBER(FIND("BIKE",RNG)),206,""))

if you need more things to check for you can add to this formula and probably the above ones as well ... but be careful that you dont have something to check for that contains two of the criteria eg CAR HIT BIKE as it will only pick the first match
Thanks John very helpful.
 
Back
Top