+ Reply to Thread
Results 1 to 11 of 11

Extract string between delimiters

  1. #1
    Registered User
    Join Date
    05-19-2014
    MS-Off Ver
    Office 2014
    Posts
    13

    Extract string between delimiters

    Greetings,

    I'm looking for a formula that will take text out between commas. I'm familiar with the left and right formulas to return things at either end, but I'm not sure how to proceed with this one. I could use the text to column, but I'm hoping to have a formula to use instead.

    expected result:
    Source ColA ColB ColC ColD ColE
    car car
    car, tree car tree
    tree, car, orange, umbrella tree car orange umbrella


    I'm open to suggestions. Each of these items has a $value. The end result is that I'm able to state how much each item contribute to that rows' cost. Groupby would be useful here

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,741

    Re: Extract string between delimiters

    I am not clear on what you are starting with and what the desired outcomes should be.

    It would help if you would upload an example Excel workbook. Please do not post pictures.

    Many of us cannot download / read these and none of us want to retype data. Hand type enough data to get

    the idea across and the layout you envision with expected results. Include any additional details in the workbook. Desensitize the data.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done"

  3. #3
    Forum Contributor
    Join Date
    06-21-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Extract string between delimiters

    Mid is pretty fancy when combined with find.

    Find(",",A1)

    That will find the first comma in cell A1. So if you want the second comma as well, just set the first comma as the starting point for a find.

    Find(",",A1,find(",",A1))

    Make sense?

    Then you can extract everything between those two points with mid.

    Mid(A1,find(",",A1),Len(A1)-find(",",A1,find(",",A1)))

    Hammered out on my phone, so hopefully it's close
    Please remember to hit the Add Reputation for any member that has been helpful.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Extract string between delimiters

    Another option...
    A
    B
    1
    car, tree car tree
    2
    car
    2
    3
    tree
    2

    B2=(LEN($A$1)-LEN(SUBSTITUTE($A$1,A2,"")))/LEN(A2)
    copied down
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    05-19-2014
    MS-Off Ver
    Office 2014
    Posts
    13

    Re: Extract string between delimiters

    Quote Originally Posted by soberguy View Post
    Mid is pretty fancy when combined with find.

    Find(",",A1)

    That will find the first comma in cell A1. So if you want the second comma as well, just set the first comma as the starting point for a find.

    Find(",",A1,find(",",A1))

    Make sense?

    Then you can extract everything between those two points with mid.

    Mid(A1,find(",",A1),Len(A1)-find(",",A1,find(",",A1)))

    Hammered out on my phone, so hopefully it's close
    Thanks I will give this a shot

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extract string between delimiters

    Try this...

    Data Range
    A
    B
    C
    D
    E
    F
    1
    2
    car
    car
    3
    car, tree
    car
    tree
    4
    tree, car, orange, umbrella
    tree
    car
    orange
    umbrella
    5
    ------
    ------
    ------
    ------
    ------
    ------


    This formula entered in B2:

    =TRIM(MID(SUBSTITUTE(","&$A2,",",REPT(" ",100)),COLUMNS($B2:B2)*100,100))

    Copy down to B4 then across until you get a column full of blanks.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Extract string between delimiters

    OK, I took the approach to count how many times a word appeared, so the $ value could be applied to that

  8. #8
    Registered User
    Join Date
    05-19-2014
    MS-Off Ver
    Office 2014
    Posts
    13

    Re: Extract string between delimiters

    Quote Originally Posted by Tony Valko View Post
    Try this...

    Data Range
    A
    B
    C
    D
    E
    F
    1
    2
    car
    car
    3
    car, tree
    car
    tree
    4
    tree, car, orange, umbrella
    tree
    car
    orange
    umbrella
    5
    ------
    ------
    ------
    ------
    ------
    ------


    This formula entered in B2:

    =TRIM(MID(SUBSTITUTE(","&$A2,",",REPT(" ",100)),COLUMNS($B2:B2)*100,100))

    Copy down to B4 then across until you get a column full of blanks.
    This works. Can you explain why trim?

    Also thanks Fdibbins for looking at it differently.

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extract string between delimiters

    The SUBSTITUTE function (virtually) replaces the commas with 100 space characters:

    The underscores represent the space characters.

    __________car__________

    So, we need the TRIM function to remove those space characters for our final result:

    TRIM("__________car__________") = car

  10. #10
    Registered User
    Join Date
    05-19-2014
    MS-Off Ver
    Office 2014
    Posts
    13

    Re: Extract string between delimiters

    Quote Originally Posted by Tony Valko View Post
    The SUBSTITUTE function (virtually) replaces the commas with 100 space characters:

    The underscores represent the space characters.

    __________car__________

    So, we need the TRIM function to remove those space characters for our final result:

    TRIM("__________car__________") = car
    That's a very elegant solution. Thanks for explaining.

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extract string between delimiters

    You're welcome. Thanks for the feedback!


    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

+ 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. [SOLVED] Very Quick Question-Select Case-Determine if string has delimiters
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-29-2013, 12:40 AM
  2. Spit string without delimiters
    By jamesstorx in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-30-2011, 06:14 PM
  3. Working with multiple delimiters in a string
    By ammauric in forum Excel General
    Replies: 6
    Last Post: 04-13-2011, 10:12 AM
  4. parsing string based on multiple delimiters
    By emceemic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2010, 11:35 AM
  5. [SOLVED] Extract based on Delimiters
    By ssjody in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2005, 11:30 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