+ Reply to Thread
Results 1 to 5 of 5

Extract a Sentence, That Contain One of these Words, from Text

  1. #1
    Forum Contributor
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    102

    Extract a Sentence, That Contain One of these Words, from Text

    Hi,

    I need to extract a sentence from the text in column A which contains one of the words (i.e. "pictures","memory","video","features"). I created a formula which extracts all text which contains one of the prescribed words but need to extract only a sentence with either of these words.

    =IF(OR(ISNUMBER(SEARCH({"pictures","memory","video","features","capacity","price","quality"},A2))),A2," ")

    Can someone help me please to create a new formula for this action?

    I attached a workbook with the sample data.

    Thanks so much!
    Attached Files Attached Files

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Extract a Sentence, That Contain One of these Words, from Text

    Hi,

    You don't say what the result should be if more than one of the search strings is found. This will return the sentence containing the first found of your search strings (as listed from left to right):

    =IFERROR(TRIM(MID(SUBSTITUTE("."&A3,".",REPT(" ",999)),LOOKUP(2^15,SEARCH({"pictures","memory","video","features","capacity","price","quality"},SUBSTITUTE("."&A3,".",REPT(" ",999))))-499,999))&".","")

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Forum Contributor
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    102

    Re: Extract a Sentence, That Contain One of these Words, from Text

    Hi XOR LX,

    The formula works perfectly! Can you please explain the logic behind it?

    thanks so much!

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Extract a Sentence, That Contain One of these Words, from Text

    You're welcome!

    In a nutshell:

    1) Replace all occurrences of "." in the string with a large number of blank spaces (999 to be precise)

    2) Find the position of the first occurrence of one of the search strings in this newly-formed string

    3) Subtract 499 from this value. This is almost certain to be before the start of the sentence containing that word (unless you have a very long sentence!), though not encroaching on the previous sentence. Somewhere in the large blank void in between...

    4) Apply a string length of 999. This will go from the blank void through the required sentence and into the second blank void.

    5) Trim the result

    Note that the formula may fail if you have occurrences of "." in the string which are not used to mark the end of sentences, e.g. in numbers/dates. And, as I mentioned, if you have some extremely long sentences (don't apply it to Saramago's works).

    Regards

  5. #5
    Forum Contributor
    Join Date
    11-21-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    102

    Re: Extract a Sentence, That Contain One of these Words, from Text

    Got it! Much appreciated!

+ 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. Replies: 7
    Last Post: 02-25-2014, 02:00 AM
  2. [SOLVED] How to extract first few words from a sentence - Help please
    By rehana357 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-06-2013, 04:09 AM
  3. Help! Count how many words in a sentence match a dictionary of words
    By sonyaelis in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2013, 05:31 AM
  4. Compare two text cells and extract common text words
    By ghost_chip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2012, 06:07 AM
  5. extract last three words from sentence
    By wheelscpa in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-19-2008, 07:52 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