+ Reply to Thread
Results 1 to 9 of 9

Find / Extract Word & Words after a Specific Word

  1. #1
    Registered User
    Join Date
    11-30-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    69

    Find / Extract Word & Words after a Specific Word

    I want to be able to get any number of words (nth words) after a specific word. I found a formula like this online (which I can't find again and I am not sure if it was after a specific word or simply spaces) and all I had to do was change a number for the number for words I wanted to retrieve--i.e. 1 for 1, 2 for 2, and so on. I am thinking maybe it was using the substitute function.

    So, to illustrate what I want, let's say I have the following in Column A

    Today is a Bob wonderful day.
    What day is it today Bob one Two Three
    Office Supplies Testing Five Seven Bob Nine Ten Twelve Thirteen


    In Column B, I want only one word after Bob, so it would have:

    wonderful
    one
    Nine

    In Column C, I want only two words after Bob, so it would have:

    wonderful day.
    one Two
    Nine Ten

    In Column D, I want only three words after Bob, so it would have:

    (I am not sure what gets shown here in this case or an error, since there are only two words)
    one Two Three
    Nine Ten Twelve

  2. #2
    Registered User
    Join Date
    11-30-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    69

    UPDATE: Re: Find / Extract Word & Words after a Specific Word

    I was able to locate the Excel file I had the formula. It was actually finding the number of words starting from the first word / character. Also, it wasn't 1 for 1 word and 2 for 2 words, but 100 for 1 and 200 for 2 and so on. Here is the formula and hopefully it helps someone in helping me out.

    Please Login or Register  to view this content.
    for one word

    Please Login or Register  to view this content.
    for two words

    I want this, but after a specific word / starting from a specific word.

  3. #3
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Find / Extract Word & Words after a Specific Word

    If your text strings are in column A, starting in A1, then try the following formula in B1:

    =TRIM(LEFT(SUBSTITUTE(MID($A1,SEARCH("bob",$A1)+LEN("bob")+1,LEN($A1))," ",REPT(" ",100)),COLUMN(A:A)*100))

    Fill down through column B and fill right as far as you need to and it should work. When you're asking for more words than remain (like in D1 of your sample), it will return whatever is left of the sentence. You can replace the two instances of "bob" (the search is not case sensitive) with a cell reference for greater flexibility
    Attached Files Attached Files
    If your problem has been solved, please use "Thread Tools" to mark the thread as "Solved".

    If you're grateful for this site's existence and would like to contribute to the community, please consider posting something hilarious in our joke thread:
    https://www.excelforum.com/the-water...ke-thread.html

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Find / Extract Word & Words after a Specific Word

    Enter formula in B1 and drag it across to E1 and down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Excel 2016 (Windows) 32 bit
    A
    B
    C
    D
    E
    1
    Today is a Bob wonderful day wonderful wonderful day wonderful day wonderful day
    2
    What day is it today Bob one Two Three one one Two one Two Three one Two Three
    3
    Office Supplies Testing Five Seven Bob Nine Ten Twelve Thirteen Nine Nine Ten Nine Ten Twelve Nine Ten Twelve Thirteen
    Sheet: Sheet1
    Last edited by AlKey; 07-05-2017 at 12:34 PM.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Registered User
    Join Date
    11-30-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Find / Extract Word & Words after a Specific Word

    In response to CAntosh (I didn't see the 2nd solution until just now and haven't tried it yet), thank you very much. On my first try I thought there was a problem, but then I realized it was due to my text having a double space, which I thought the Trim function took care of.

    So, if I have the following text:

    Hello Hello One Bob Three Five Seven Eight

    with two spaces after the word Five

    These are the results I get:

    One word: Three
    Two words: Three Five
    Three words: Three Five
    Four words: Three Five Seven (without the two spaces after Five, so I guess this is when the Trim function is being applied).

    I will just remove the double spaces but will also take a look at the 2nd formula to see how it reacts in this scenario.

    Once again, thanks.

  6. #6
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Find / Extract Word & Words after a Specific Word

    Good catch on the double spaces. Apologies. Al's solution appears to account for those, so his is probably the one to use!

  7. #7
    Registered User
    Join Date
    11-30-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Find / Extract Word & Words after a Specific Word

    In response to AlKey:

    Thank you very much. Your solution doesn't have the problem I described in my previous post about double space. One thing I noticed though is that it is case sensitive--the word I am searching for in the formula must be in the same case as the word in the text.

    Also, to both of CAntosh and AlKey, if you all don't mind, could you explain a bit / break down the steps as to what the formula is doing / how it works? To AlKey, what's with the triple 100's; What's happening there: REPT(" ",100)),100,100))

  8. #8
    Registered User
    Join Date
    11-30-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Find / Extract Word & Words after a Specific Word

    Isn't it just a matter of sticking another Trim right before the Substitute function like AlKey's solution? I tried doing so, but don't know if it's because this won't work or if I am sticking the parentheses in the wrong spot, but I can't get a valid formula created when I enter another Trim.

  9. #9
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Find / Extract Word & Words after a Specific Word

    The 100s are a way of spacing out words to make them easy to find. If I take "See spot run" and turn each space into 100 spaces, then I know that looking at the first 100 characters will return just the first word. The first 200 characters will contain exactly two words, etc. It is then paired with TRIM to cut the spaces back down. AlKey's solution uses a similar strategy to replace the search term with spaces, enabling the formula to identify only the words after the term. Use "Evaluate Formula" on the 'Formula' tab to walk through the formula and see it in action.

    If you're dealing with really long text strings in column A (100+ characters), you may want to change them to 1000s in AlKey's solution.

    If you want to revise my solution to handle double spaces, it needs an extra TRIM; try the following:
    =TRIM(LEFT(SUBSTITUTE(TRIM(MID($A1,SEARCH("bob",$A1)+LEN("bob")+1,LEN($A1)))," ",REPT(" ",100)),COLUMN(A:A)*100))

+ 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: 1
    Last Post: 02-21-2016, 02:39 AM
  2. [SOLVED] Help with macro to find a specific word and replace the entire cell with the return word.
    By BG1983 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-24-2015, 09:40 PM
  3. [SOLVED] How to find specific word and sum the column according to that word
    By cobo1981 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-14-2014, 12:04 PM
  4. Extract words/numeric after each specific word
    By chweetvjy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-22-2014, 06:40 AM
  5. [SOLVED] extract the first two words (or take out the last word)
    By rickytj in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-09-2013, 11:58 PM
  6. How to find a specific word and replace the immediate next word
    By sugaprasad in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-31-2013, 02:16 AM
  7. search for a specific word and copy the word and the preceeding words until a comma
    By DHANANJAY in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-31-2005, 09:10 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