+ Reply to Thread
Results 1 to 12 of 12

Using "if" function to look for strings containing a specific text, in multiple cells

  1. #1
    Registered User
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Using "if" function to look for strings containing a specific text, in multiple cells

    Hi everyone

    I'm trying to sort through a large text file, containing multiple cells. I'm using the function =IF(ISNUMBER(SEARCH("*hit*",G5)),"1","0"). This returns 1 if the text in G5 contains the string "hit". It works fine, but only if I do it on one cell, and I'm trying to do the search in multiple cells.
    Is there a way to do that?
    Thank you!

  2. #2
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    hit.xlsx
    Please see attached
    Array formula
    =SUM(--(ISNUMBER(SEARCH("hit",$G$4:$G$30))))
    This will count how many times this word is within your column
    Last edited by RobertMika; 11-21-2013 at 12:59 AM.
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  3. #3
    Forum Contributor amit.wilson's Avatar
    Join Date
    07-09-2013
    Location
    Gotham
    MS-Off Ver
    Excel for Mac 2011
    Posts
    283

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    T - welcome to the forum. What output are you looking for: the count of "hit" occurrences in a range or the address of cells with "hit" in them?

    Cheers
    <-- If you're happy & you know it...click the star.:-)

  4. #4
    Registered User
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    Thank you!
    I just want to know whether or not the string "hit" appears anywhere in those cells. I want it to return 1 if it appears, 0 if not.

  5. #5
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    maybe also countif ???

    =--(COUNTIF(A1:A10,"*hit*")>0)
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  6. #6
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    welcome to the forum, Tamar. SEARCH is actually already looking for partial text, so that's why you don't need the wildcards. 1 & 0 are numbers, so you don't need the double quotes too.
    =IF(ISNUMBER(SEARCH("hit",G5)),1,0)

    and if you want to do a range & don't wish to press CTRL + SHIFT + ENTER, you could use:
    =IF(SUMPRODUCT(--(ISNUMBER(SEARCH("hit",$G$4:$G$30))))>0,1,0)

    but actually COUNTIF will do. now you need the wildcards:
    =IF(COUNTIF($G$4:$G$30,"*hit*"),1,0)

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  7. #7
    Registered User
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    I've used Vlady method and it seems to work! Thank you!
    Just a quick follow up question - if I need to o the same, but with "and" or "or" - meaning, return 1 if somewhere in those next 10 cells there is "hit" or "direct", or return one if there is "hit" and "direct" - how do I do that?
    Thanks again!

  8. #8
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    =IF(SUM(COUNTIF($G$4:$G$30,{"*hit*","*direct*"})),1,0)

  9. #9
    Registered User
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    Thank you! Will that give me "or" or "and"?

  10. #10
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    thank Robert
    also you can try the doule - to turn true/false to 1/0

    =--(SUM(COUNTIF(A1:A9,{"*hit*","*direct*"}))>0)

  11. #11
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    This is the AND.
    If you cell has both values "hit" and "direct" use just this part
    =--(SUM(COUNTIF(A1:A9,{"*hit*","*direct*"}))
    to get the overall count.

  12. #12
    Registered User
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Using "if" function to look for strings containing a specific text, in multiple cells

    Thank you so much y'all!

    One more question - if I want - for another use - that excel will copy the whole cell to another location if it contains (not equal!) a specific string - e.g., I have coco_hit_5 and I want to copy all of it since it contains "hit" - how do I do that? I tried doing it with advanced filter but I don't want it to effect the row, just specific cells.
    Thank you!

+ 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. [SOLVED] Formula Needed to fill multiple cells with "No" when the word "No" is entered into a cell
    By excelteam777 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-09-2013, 05:36 PM
  2. [SOLVED] "If" function with Multiple Ref Cells in Text and Return Value
    By cychua in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-05-2013, 07:26 AM
  3. Replies: 9
    Last Post: 09-05-2012, 10:23 AM
  4. [SOLVED] Find multiple "text" criteria and return as ""Yes" in Matrix
    By bertrand82 in forum Excel General
    Replies: 11
    Last Post: 04-30-2012, 09:20 AM
  5. Replies: 1
    Last Post: 02-08-2005, 03:06 PM

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