+ Reply to Thread
Results 1 to 8 of 8

Need to chck if a keyword is present in a text string and return keyword if yes

  1. #1
    Registered User
    Join Date
    12-15-2012
    Location
    Latvia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Need to chck if a keyword is present in a text string and return keyword if yes

    Dear friends,

    I've got a column with addresses as a text string. Text may contain name of a street, city, house number etc. Besides there is no strict order that name of street should come first, it can be anywhere in a text string. Another table contains two columns: first one with keywords (street name as a keyword) and second column contains relevant postal code. I need to check if any keywords from second table is present in each cell of column with addresses, if yes then return name of street (keyword) or postal code relevant to this keyword. I'll be very grateful for your help! Regards, JekaterinaExample.xls

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Need to chck if a keyword is present in a text string and return keyword if yes

    Based on your sample file, try this, copied down...
    =IF(ISNUMBER(SEARCH(E2,A2,1)),E2,IF(ISNUMBER(SEARCH(F2,A2,1)),F2,""))

    edit: this searches for either the keyword (returns keyword) or postal code (returns postal code)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Need to chck if a keyword is present in a text string and return keyword if yes

    try it
    =IF(ISNUMBER(FIND(E2;A2));E2;"No")

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Need to chck if a keyword is present in a text string and return keyword if yes

    Put this array* formula in B2:

    =IF(MAX(IF(ISNUMBER(SEARCH(E$2:E$6,A2)),ROW(E$2:E$6)))=0,"",INDEX(E:E,MAX(IF(ISNUMBER(SEARCH(E$2:E$6,A2)),ROW(E$2:E$6))))) & IF(MAX(IF(ISNUMBER(SEARCH(F$2:F$6,A2)),ROW(F$2:F$6)))=0,"",INDEX(F:F,MAX(IF(ISNUMBER(SEARCH(F$2:F$6,A2)),ROW(F$2:F$6)))))

    then copy down.

    *An array formula needs to be committed using the key combination of Ctrl-Shift-Enter (CSE) instead of the usual Enter.

    Hope this helps.

    Pete

    EDIT: Sorry, you won't be able to use the full-column references in the arry formula as you have XL2003 - try this one instead:

    =IF(MAX(IF(ISNUMBER(SEARCH(E$2:E$6,A2)),ROW(E$2:E$6)))=0,"",INDEX(E$1:E$6,MAX(IF(ISNUMBER(SEARCH(E$2:E$6,A2)),ROW(E$2:E$6))))) & IF(MAX(IF(ISNUMBER(SEARCH(F$2:F$6,A2)),ROW(F$2:F$6)))=0,"",INDEX(F$1:F$6,MAX(IF(ISNUMBER(SEARCH(F$2:F$6,A2)),ROW(F$2:F$6)))))

    Still committed with CSE.

    File attached to demonstrate.

    Pete
    Attached Files Attached Files
    Last edited by Pete_UK; 12-16-2012 at 04:52 PM.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Need to chck if a keyword is present in a text string and return keyword if yes

    @ Ghozi, nice 1 note though that "find" looks for an exact match (upper and lower), while "search" ignores case. in the examples provided, your formula will work perfectly but if the case of just 1 letter was changed, it would fail

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need to chck if a keyword is present in a text string and return keyword if yes

    Where would you like the Keyword or Code Returned - Or are you asking for a function??
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  7. #7
    Registered User
    Join Date
    12-15-2012
    Location
    Latvia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need to chck if a keyword is present in a text string and return keyword if yes

    Thanks Pete! It is just brilliant!

  8. #8
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Need to chck if a keyword is present in a text string and return keyword if yes

    You could try this one, although it does use a helper column:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See attachment
    Attached Files Attached Files
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

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