+ Reply to Thread
Results 1 to 10 of 10

search function

  1. #1
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293

    search function

    hello,

    please see attached spreadsheet, what i would like for it to do is

    search column a for any word/phrase that contains "dog", if it does display number next to , i.e. the one in column b, if when searching for "dog" or any variation where "dog" isnt contained in phrase, display a blank

    desired result is in column f and column g.

    thanks
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523
    Hi,
    Try this code,
    Please Login or Register  to view this content.
    Attached is a sample of it in use....
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,943
    1) =IF(ISERR(SEARCH("dog",A2,1)),"",A2), copies the phrase
    2) =IF(ISERR(SEARCH("dog",A2,1)),"",B2), copies the adj. value
    Ben Van Johnson

  4. #4
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293
    Quote Originally Posted by protonLeah View Post
    1) =IF(ISERR(SEARCH("dog",A2,1)),"",A2), copies the phrase
    2) =IF(ISERR(SEARCH("dog",A2,1)),"",B2), copies the adj. value

    thanks worked perfectly. also thanks davesexcel, apprecciate ur help, the simpler formula makes more sense to me

    would iserror also not work?

    lastly, if i want to include in the search and or "cats", would it be..? getting some kind of error...

    =IF(ISERRor(and(or(SEARCH("dog","cats",A2,1)),"",A2)
    Last edited by VegasL; 09-07-2008 at 07:19 PM.

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    just add the same thing for cats

    =IF(ISERR(SEARCH("dog",A2,1)),"",A2)&IF(ISERR(SEARCH("cat",A2,1)),"",A2)

    =IF(ISERR(SEARCH("dog",A2,1)),"",B2)&IF(ISERR(SEARCH("cat",A2,1)),"",B2)
    dragged down will return dogs and cats
    and yes
    iserror will work
    Last edited by martindwilson; 09-07-2008 at 07:31 PM.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    If you have more crtieria then try

    =IF(SUM(COUNTIF(A2,{"cat","dog"}))>0,A2,"")
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  7. #7
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293
    =IF(SUM(COUNTIF(A2,{"cat","dog"}))>0,A2,"") returned empty for all cells.

    i may have up to 10 criteria i.e. cat, dog, chicken, hen , etc..

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Does A2 have the condition. If anywhere in the string try

    =IF(SUM(COUNTIF(A2,{"*cat*","*dog*"}))>0,A2,"")
    VBA Noob

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    =IF(SUM(COUNTIF(A2,{"cat","dog"}))>0,A2,"") returned empty for all cells.
    that coz its looking for exact match of "dog" ,"cat"
    you need search so it finds the string
    ah ah i see a wild card function above didn't know you could do that
    Last edited by martindwilson; 09-12-2008 at 04:27 PM.

  10. #10
    Forum Contributor
    Join Date
    02-10-2007
    MS-Off Ver
    Excel 2010
    Posts
    293
    Thanks VBANoob. =IF(SUM(COUNTIF(A2,{"*cat*","*dog*"}))>0,A2,"") worked perfectly, appreciate your help.

    I wasn't aware of countif applied to Text as well, thought it only applied to Numbers.



    I'm understanding it as, Countif (lookfor "*cat", or "*dog*") within cell a2, only if those specific values exist, because (sum>0 (not sure why/why sum>0), else display cell a2, otherwise display "".

    Could you translate above equation?, I'm sure I'm not reading it right?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Search and Left Function
    By VegasL in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-15-2008, 03:09 PM
  2. Search Function
    By bunny1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2008, 09:30 AM
  3. Help with doing a "contains" function or search
    By Profiteer23 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-30-2008, 12:04 AM
  4. SEARCH function, help needed!
    By prince.ali in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-01-2007, 06:44 PM
  5. Assistance with data search function
    By stellakebab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2007, 11:46 AM

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.6.0 RC 1