+ Reply to Thread
Results 1 to 10 of 10

Extract string based on specific string

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Extract string based on specific string

    Hello everybody
    I have this value for example
    My name is Yasser Khalil
    I want to extract the name and the address based on the string (My name is) to extract (Yasser Khalil) the name consists of two parts (first name and second name) ..
    I also want to extract the address based on the string(and the address is) to extract the rest of the string(20 Salem st.,Cairo)
    Thanks advanced

    I appreciate if it can be done with a UDF function

    Moderator's note: Personal info removed, never a good idea to show that kind of info on public forum
    Last edited by FDibbins; 12-13-2014 at 05:42 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract string based on specific string

    A2: given text string
    B2: =TRIM(LEFT(MID(SUBSTITUTE($A2, " ", REPT(" ", 30)), FIND("is", SUBSTITUTE($A2, " ", REPT(" ", 30)))+30, 100), 30))
    C2: =TRIM(LEFT(MID(SUBSTITUTE($A2, " ", REPT(" ", 30)), FIND("is", SUBSTITUTE($A2, " ", REPT(" ", 30)))+60, 100), 30))
    D2: =MID($A2, FIND($C2, $A2)+LEN($C2)+19,1000)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Extract string based on specific string

    Hello YasserKhalil,

    I think this thread of yours may be related to this one; http://www.excelforum.com/excel-prog...tion-list.html

    Please forgive me if I am wrong.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Extract string based on specific string

    Thanks Mr. JBeaucaire for this great solution.. But I'm wondering for a simple formula or udf function that I can type part of my string to get the next string:
    for example:
    Please Login or Register  to view this content.
    But I got the string (My name is ) in the result..

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Extract string based on specific string

    See if this helps.
    Please Login or Register  to view this content.
    Then use it like this.....

    To get the Name
    Please Login or Register  to view this content.
    To get the Address
    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Extract string based on specific string

    Mr. sktneer
    really wonderful function from wonderful professional expert..
    I want to learn how to do such magic lines

    Is there a way to add an argument to specify which occurence of specific word and extract what follows:
    for example: I have two "is" I want to specify the first or second and based on its occurence extract the string which follows
    Last edited by YasserKhalil; 12-13-2014 at 03:28 PM.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Extract string based on specific string

    You may try something like this....
    Please Login or Register  to view this content.
    So if your string is
    Please Login or Register  to view this content.
    Then to get the Name, try
    Please Login or Register  to view this content.
    And to get the Address, try
    Please Login or Register  to view this content.
    And if you string is like this...
    Please Login or Register  to view this content.
    Then to get the Name, try
    Please Login or Register  to view this content.
    And to get the Address, try
    Please Login or Register  to view this content.
    Is this what you are trying to achieve?

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Extract string based on specific string

    Great Mr. sktneer
    you are about to achieve my goal ...
    I want the strings "name" and "address" to be variables not constants .. so as to make use of this fantastic function in extracting what I want to extract
    Thank you very much for great help

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract string based on specific string

    I'm not seeing what was wrong with the formulas from post #2 based on your original question. They didn't work for you?

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Extract string based on specific string

    Mr. JBeaucaire
    formulas are perfect
    But the string was just an example to learn how to extract desired texts from strings..
    I was searching for simple way such as UDF which may look like that:
    =MyUDF("substring",A1,Nth occuerence) >> to get the string which follows that substring
    for example:
    the string (I like to learn. I want to learn VBA) in A1
    After using =MyUDF("learn",A1,2) to get the result VBA

+ 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. Extract specific numbers from a string of text
    By Galwaygirl13 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-19-2012, 03:22 PM
  2. Extract specific word from a text string
    By krjoshi in forum Excel General
    Replies: 10
    Last Post: 01-19-2012, 02:00 PM
  3. Extract String After Specific Word
    By Gingeiko in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2011, 09:05 AM
  4. Replies: 11
    Last Post: 09-29-2011, 04:42 AM
  5. [SOLVED] Extract specific value from a long text string
    By Dinesh in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-10-2006, 11:30 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