+ Reply to Thread
Results 1 to 6 of 6

Extract all text strings after a specific text string

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2013
    Posts
    3,120

    Extract all text strings after a specific text string

    I'm compiling a cheat sheet of formulas for my office workers to use. When I get to the Text functions, I can find examples of how to do just about everything except extract text before/after a particular string. I've found a few formulas for doing it after a symbol, but they don't work when it comes to a string.

    For example, say I have 15 paragraphs that all begin with "Yo mamma's so ugly that..." and I want to extract whatever follows after "that". Or, say I have 1000 lines of text formatted
    Please Login or Register  to view this content.
    and I want to extract everything after the 4th character string (HERD in this example), or before the 4th string. Is there a way to do that in a formula that can adapted to any situation?

    Your help in augmenting my knowledge is already greatly appreciated.

    Thanks,
    John
    Last edited by jomili; 05-03-2011 at 09:55 AM.

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

    Re: Extra all text strings after a specific text string

    for after with phrase entered in a1 key phrase/word in b1
    =TRIM(MID(A1,SEARCH(B1,A1)+LEN(B1),255)
    and for before
    =TRIM(LEFT(A1,SEARCH(B1,A1)-1))
    "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
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2013
    Posts
    3,120

    Re: Extra all text strings after a specific text string

    Martin,

    You are a wizard and I thank you. Your two formulas are easy to use and easy to adapt to changing situations. But there's still one piece I need; if I don't know the phrase, but I do know it's position (2nd word in the string, or 4th, whatever) how would I use that in the formulas you've presented?

    And, in case I didn't make it clear, THANK YOU, THANK YOU, THANK YOU for the formulas you've provided so far!

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

    Re: Extra all text strings after a specific text string

    to get everything from word n where b1 contains the number of word
    =MID(A1,FIND("~",SUBSTITUTE(A1," ","~",B1-1))+1,255) is the nth word onwards
    before the nth word
    =LEFT(A1,FIND("~",SUBSTITUTE(A1," ","~",B1-1))-1)
    and before and inc nth word
    =LEFT(A1,FIND("~",SUBSTITUTE(A1," ","~",B1))-1)

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,643

    Re: Extract all text strings after a specific text string

    or in VBA
    the second word in each cell (result in column B)

    Please Login or Register  to view this content.
    the third word in each cell
    Please Login or Register  to view this content.
    the text before the second word:
    Please Login or Register  to view this content.
    the text after the second word:
    Please Login or Register  to view this content.



  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Excel 2013
    Posts
    3,120

    Re: Extract all text strings after a specific text string

    My Sweet Lord! All I wanted was a simple formula, and got that in spades, and equivalent VBA procedures to boot. ALL of this stuff is going into my toolbox. Martin and SNB I can't thank you enough. I think with the addition of these tools there's not much with text that I'm not going to be able to do.

    THANK YOU, thank you, THANK YOU, Thank You, THANK YOU!

+ 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