+ Reply to Thread
Results 1 to 8 of 8

Excel - Get the Word to the Left or Right of Another Word (text string)

  1. #1
    Registered User
    Join Date
    04-21-2009
    Location
    Puyallup, WA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Excel - Get the Word to the Left or Right of Another Word (text string)

    I am trying to figure out how to get the WHOLE word to the left or right of an anchor term using a formula.

    For example:

    IF anchor term = 'excel formula'

    Word to left or right.PNG

    Here is a sample workbook:
    Word to Left or Right Formula.xlsx

    I'm sure this is a simple len formula but I run into issues if the word has white space in the front and back or doesn't.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Excel - Get the Word to the Left or Right of Another Word (text string)

    =LEFT(TRIM(A1),FIND(" ",TRIM(A1))-1)
    and
    =TRIM(RIGHT(SUBSTITUTE(TRIM(A1)," ",REPT(" ",50)),25))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    04-21-2009
    Location
    Puyallup, WA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Excel - Get the Word to the Left or Right of Another Word (text string)

    Thanks for the help. The formula is not quite right. I only need the word to the immediate left or right of the focus word.

    Example: if the phrase is "buy new home siding today now"

    I don't need:
    Left - "buy new home"
    Right - "today now"

    I do need:
    Left - "home"
    Right - "today"

    Example Output.xlsx

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Excel - Get the Word to the Left or Right of Another Word (text string)

    thats not clear
    chicago roof companies
    why not chicago and companies ?

  5. #5
    Registered User
    Join Date
    04-21-2009
    Location
    Puyallup, WA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Excel - Get the Word to the Left or Right of Another Word (text string)

    Going back to my original question, I am trying to figure out how to get the WHOLE word to the left or right of an anchor term using a formula.

    Said another way, I want to get the immediate word to the left or right of another word in a phrase.

    Your formulas get the beginning word and the ending word of a phrase. That's not what I'm trying to do.

    I am trying to get the immediate word to the left and right of an ANCHOR term.

    Another example.xlsx

    In your example:
    "chicago roof companies"

    Why not chicago (left) and companies (right).

    Answer: Yes, that would be correct but only since this is a 3-word phrase.

    Let's say it was a 4-word phrase:
    "chicago IL roof companies"

    The LEFT word I want is "IL" and not "chicago" or "chicago IL". I just want the immediate word to the left of "roof" which would be "IL".

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Excel - Get the Word to the Left or Right of Another Word (text string)

    ok next stab.....
    Attached Files Attached Files

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

    Re: Excel - Get the Word to the Left or Right of Another Word (text string)

    for left column
    =TRIM(RIGHT(SUBSTITUTE(" "&TRIM(LEFT($A2,FIND("excel formula",$A2)-1))," ",REPT(" ",LEN($A2))),LEN($A2)))

    for right column
    =TRIM(LEFT(SUBSTITUTE(MID($A2,FIND("excel formula",$A2)+LEN("excel formula")+1,LEN($A2))," ",REPT(" ",LEN($A2))),LEN($A2)))

  8. #8
    Registered User
    Join Date
    04-21-2009
    Location
    Puyallup, WA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Excel - Get the Word to the Left or Right of Another Word (text string)

    martindwilson - thanks but when I open your solution, the "right word" formula has a #NAME? error.

    Ghozi Alkatiri - Thank you! Your solution solves finding the immediate word to the left or right of a certain word within a phrase.

    Thanks to you both for offering your time and knowledge. Rep Given.

+ 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: 2
    Last Post: 08-05-2013, 04:45 PM
  2. [SOLVED] find word in string, count how many special characters are to its left
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2013, 06:46 PM
  3. [SOLVED] How to conditionally insert text string into a line after first word using Word 2010
    By staggers47 in forum Word Formatting & General
    Replies: 5
    Last Post: 12-08-2012, 11:07 AM
  4. Replies: 9
    Last Post: 11-20-2012, 08:47 AM
  5. WORD-DELIMITED string vba macro for excel/word
    By jackal2k6 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2005, 12:35 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