+ Reply to Thread
Results 1 to 7 of 7

Help Needed: Extract text string using very specific criteria

  1. #1
    Registered User
    Join Date
    04-18-2014
    Location
    San Francisco
    MS-Off Ver
    Mac Excel 2011
    Posts
    8

    Help Needed: Extract text string using very specific criteria

    Hi!

    I need help figuring out a formula to extract text.

    All of the cells are made up of identifiers that have text broken up by dashes into separate "identifiers".
    For example:
    "M-AND-JHH-EHJ-SF-D-Q"
    "F-STRR-HJ-HL-NH-BLGR-L"

    I want to be able to extract the middle 4 identifiers, using the dashes (since the character count differs for each one).
    Is there a way to do this??

    Basically, something similar to the Mid function, but does not depend on counting characters from the beginning....

    Thanks!

  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: Help Needed: Extract text string using very specific criteria

    what are the middle 4?
    F-STRR-HJ-HL-NH-BLGR-L
    STRR-HJ-HL-NH
    or
    HJ-HL-NH-BLGR
    "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
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,375

    Re: Help Needed: Extract text string using very specific criteria

    Hi Sajo90 and welcome to the forum.

    This formula should do what you need.
    =SUBSTITUTE(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",LEN(A2))),LEN(A2)*2,LEN(A2)*4))," ","-")

    See the attached for proof.

    I agree with Martin that the "middle 4" may be a problem if there are only 2 dashes.
    Attached Files Attached Files
    Last edited by MarvinP; 04-18-2014 at 08:07 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    04-18-2014
    Location
    San Francisco
    MS-Off Ver
    Mac Excel 2011
    Posts
    8

    Thumbs up Re: Help Needed: Extract text string using very specific criteria

    Hi!

    Thanks Marvin, that works perfectly...
    Sorry, I realize I wasn't clear on the middle four..


    Can you let me know how the formula would be altered if I wanted to include the first 6?

    Ex:

    M-AND-JHH-EHJ-SF-D
    from
    "M-AND-JHH-EHJ-SF-D-Q"

    THANK YOU!

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

    Re: Help Needed: Extract text string using very specific criteria

    Quote Originally Posted by Sajo90 View Post
    ...if I wanted to include the first 6?...
    Hello,

    Here is one way:

    =LEFT(A1,FIND("^",SUBSTITUTE(A1,"-","^",6))-1)
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  6. #6
    Registered User
    Join Date
    04-18-2014
    Location
    San Francisco
    MS-Off Ver
    Mac Excel 2011
    Posts
    8

    Re: Help Needed: Extract text string using very specific criteria

    Thanks Haseeb!

    That worked very well as well.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,375

    Re: Help Needed: Extract text string using very specific criteria

    Change in this formula
    =SUBSTITUTE(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",LEN(A2))),LEN(A2)*2,LEN(A2)*4))," ","-")
    to
    =SUBSTITUTE(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",LEN(A2))),LEN(A2)*2,LEN(A2)*6))," ","-")

    OK - here is what this fancy formula does.

    It takes each dash "-" and replaces it with a bunch of spaces. The number of spaces is the length of the original string.
    We do this knowing the TRIM() function will reduce those spaces down to a single space at the end.

    Then we simply pick which part we want and trim it down.

    Example:

    Will-this-work?
    replace all the "-" with 15 spaces. There are 15 characters in "Will-this-work?" and you get
    Will...............this...............work? (each dash is now replaced with 15 spaces)

    To extract the "this" we Trim() the above string from character 15 to 30 using the Mid() function.
    Last edited by MarvinP; 04-18-2014 at 09:31 PM.

+ 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] Extract text from a string of text (amend formula to include new criteria)
    By robertguy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-10-2013, 04:53 PM
  2. 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
  3. Extract specific word from a text string
    By krjoshi in forum Excel General
    Replies: 10
    Last Post: 01-19-2012, 02:00 PM
  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

Tags for this Thread

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