+ Reply to Thread
Results 1 to 3 of 3

Return words before and after a keyword in excel

  1. #1
    Registered User
    Join Date
    01-09-2013
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    3

    Return words before and after a keyword in excel

    Hi Everyone,

    I'm working on statistics for my local baseball team, and I would like to be able to output words before and after a key word in excel.

    When given data from each game, I get the following string as an example:

    Pitching Change: Paul McCartney replaces John Lennon.

    I would like to extract the players names ie. The first two words before the word "replaces" and the first two words after the word "replaces".

    So my desired return will be "Paul McCartney" in one cell and "John Lennon" in another.

    NOTE:
    - I tried a formula that returns the 3rd, 4th, 6th and 7th words but it does not work as sometimes players have three or four words in their names and this messes me up. This is why I need it based around the keyword "replaces". I hope this makes sense, I've tried to explain it better in the attached sheet!
    - If possible, I need the fullstop removed from the results. ie I would like "John Lennon" returned instead of "John Lennon."

    Thanks in advance
    Tom

  2. #2
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    365
    Posts
    2,243

    Re: Return words before and after a keyword in excel

    Try:

    B2,

    =MID(LEFT(A2,SEARCH("replaces",A2)-2),FIND(":",A2)+2,250)

    C2,

    =MID(A2,SEARCH("replaces",A2)+9,LEN(A2)-SEARCH("replaces",A2)-8-(RIGHT(A2)="."))

    Copy down.
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  3. #3
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Return words before and after a keyword in excel

    try the macro, I placed the results in lines 10,11

+ 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