+ Reply to Thread
Results 1 to 12 of 12

Thread: Searching for appropriate function

  1. #1
    Registered User
    Join Date
    06-14-2007
    Posts
    8

    Searching for appropriate function

    Hello All,

    I need some help looking for a function which could help me.

    I have the following scenarion:

    I need something similar to "IF" function. That I can use for if cell value contains part of a text value return 1 if not return 2

    Example:

    IF AX contains "*.*pro*.*" then BX = 1
    IF AX not contain "*.*pro*.*" then BX = 2

    Hope I made myself clear enough

  2. #2
    Forum Guru EdMac's Avatar
    Join Date
    01-23-2006
    Location
    Exeter, UK
    MS-Off Ver
    2003
    Posts
    1,264
    Try this (substitute A1 with your actual cell ref)

    =IF(ISNUMBER(SEARCH("*.*pro*",a1)),1,2)
    Ed
    _____________________________
    Always learning, but never enough!
    _____________________________

  3. #3
    Registered User
    Join Date
    07-02-2008
    Location
    Prague, Czech Republic
    Posts
    22
    You could probably use either FIND() or SEARCH() (they're exactly the same, but FIND() is case sensitive but SEARCH() is not)

    If you did SEARCH("Pro",A1), it would return the position of A1.

    If the string does not contain the string "Pro", it will bring back an error, but use ISERROR() to trap it.

    You can't use wildcard characters though, but by playing around with the SEARCH function, you should be able to get the desired result.

    So something like...

    IF(ISERROR(SEARCH("Pro",A1)),2,1)

    Once you got that sussed, have a play with this...

    There is a third argument to the SEACH() function, that is, start_number

    use this third argument to locate the . areas both before & after the 'Pro' part.

  4. #4
    Registered User
    Join Date
    06-14-2007
    Posts
    8
    thank you both for the reply will play a little bit now

  5. #5
    Registered User
    Join Date
    06-14-2007
    Posts
    8
    Last question, how can I combine in:

    IF(ISERROR(SEARCH("prov",M:M)),2,1)

    more than one find text value? I want also to find blank sell + 1 additional search creteria.

  6. #6
    Registered User
    Join Date
    07-02-2008
    Location
    Prague, Czech Republic
    Posts
    22
    Quote Originally Posted by vladmir
    Last question, how can I combine in:

    IF(ISERROR(SEARCH("prov",M:M)),2,1)

    more than one find text value? I want also to find blank sell + 1 additional search creteria.

    Can you use 'AND'?

    such as..

    IF(ISERROR(AND(SEARCH("VAL1",M:M),SEARCH("VAL2",M:M))),2,1)

    this will return 1 if both entries are present & correct

  7. #7
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636
    Try something like:

    =IF(OR(ISNUMBER(SEARCH({"prov","other_word"},M1:M100))),1,2)

    where other_word is your other text value to find.

    Note: Since you are searching in a range, rather than only in one cell, then this becomes an array formula. You must confirm it with CTRL+SHIFT+ENTER not just ENTER. You will see { } brackets appear around the formula.

    Also, unless you are on Excel2007, you cannot use whole column references such as M:M you must use a fixed range like M1:M100.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  8. #8
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636
    Quote Originally Posted by aldredd
    Can you use 'AND'?

    such as..

    IF(ISERROR(AND(SEARCH("VAL1",M:M),SEARCH("VAL2",M:M))),2,1)

    this will return 1 if both entries are present & correct
    Have you tested this?
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  9. #9
    Registered User
    Join Date
    07-02-2008
    Location
    Prague, Czech Republic
    Posts
    22
    Quote Originally Posted by NBVC
    Have you tested this?
    Nope, but yes, there is clearly something not quite right with that!

    Which made me realise that surely a much simpler way would be..

    IF(ISERROR((SEARCH("VAL1",M:M)+SEARCH("VAL2",M:M)),2,1)

  10. #10
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636
    Quote Originally Posted by aldredd
    Nope, but yes, there is clearly something not quite right with that!

    Which made me realise that surely a much simpler way would be..

    IF(ISERROR((SEARCH("VAL1",M:M)+SEARCH("VAL2",M:M)),2,1)
    Are you certain that works?...

    First, of all, it must be entered as an array formula, using CTRL+SHIFT+ENTER...

    Second, if you are not on 2007, you can't use M:M

    Third, Each of the SEARCH() functions will return a bunch of #VALUE! errors amongst any positive finds... so the ISERROR will always yield TRUE (unless every cell in the range is filled with one of the search values....). That is why I used ISNUMBER instead... because you are looking to see if there is at least one match, not at least one error....
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  11. #11
    Registered User
    Join Date
    07-02-2008
    Location
    Prague, Czech Republic
    Posts
    22
    Quote Originally Posted by NBVC
    Are you certain that works?...
    Yep
    First, of all, it must be entered as an array formula, using CTRL+SHIFT+ENTER...
    I didn't need to - work as it was
    Second, if you are not on 2007, you can't use M:M
    hmm, I only check it aginst 1 cell, rather than a range. Probably why I got away without using arrays.
    Third, Each of the SEARCH() functions will return a bunch of #VALUE! errors amongst any positive finds... so the ISERROR will always yield TRUE (unless every cell in the range is filled with one of the search values....). That is why I used ISNUMBER instead... because you are looking to see if there is at least one match, not at least one error....
    hmm, depends how you read the question I think. I took it as that he wanted to check for both conditions being present, rather than one or the other, but yes, mine would not work in that case, but does for the former.
    Even then, you could do a nested if() to check for the second criteria, Not pretty, but gets the job done

    Edit: Just tried it on a range of data, and still works without using array formula, but of course, I'm looking to match both strings, rather than either of them

  12. #12
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636
    Again, your formula is for looking at 1 cell, not a range.... so it doesn't work on a range as the OP wants.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0