+ Reply to Thread
Results 1 to 7 of 7

How to extract text from cells of varying length?

  1. #1
    Registered User
    Join Date
    09-12-2015
    Location
    France
    MS-Off Ver
    Unsure
    Posts
    6

    How to extract text from cells of varying length?

    Let's say that the cells below are A1 and A2. I want to extract text in the following format: ????-??-???-???? and place it in the cell immediately to the right (B1 and B2). In this case, the text that should be extracted would be 4210-01-208-4616 (B1) and 4820-01-208-4595 (B2). Is there a formula to do this? Much thanks in advance.

    99657 4860375 4210-01-208-4616
    99657 283281-0002 4820-01-208-4595 326 13

  2. #2
    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
    52,926

    Re: How to extract text from cells of varying length?

    Hi, welcome to the forum

    Try this, copied down...
    =MID(A1,FIND("-",A1,IF(LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))=3,1,FIND("-",A1,1)+1))-4,16)
    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

  3. #3
    Registered User
    Join Date
    09-12-2015
    Location
    France
    MS-Off Ver
    Unsure
    Posts
    6

    Re: How to extract text from cells of varying length?

    Thanks for the welcome. Unfortunately, that formula did not work. It simply returned values of "0" in Column B.

  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
    52,926

    Re: How to extract text from cells of varying length?

    It worked for me?

    A
    B
    1
    99657 4860375 4210-01-208-4616 4210-01-208-4616
    2
    99657 283281-0002 4820-01-208-4595 326 13 4820-01-208-4595


    B1=MID(A1,FIND("-",A1,IF(LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))=3,1,FIND("-",A1,1)+1))-4,16)
    copied down

  5. #5
    Registered User
    Join Date
    09-12-2015
    Location
    France
    MS-Off Ver
    Unsure
    Posts
    6

    Re: How to extract text from cells of varying length?

    That's odd. Let me try it again.

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: How to extract text from cells of varying length?

    Here are two more formulas to do that.


    =MID(A1,FIND(" ",A1,FIND(" ",A1)+1)+1,16)

    =MID(A1,SEARCH("????-??-???-????",A1),16)
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  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
    52,926

    Re: How to extract text from cells of varying length?

    AlKey, thanks for this 1...
    =MID(A1,SEARCH("????-??-???-????",A1),16)

    I tried that too, but used FIND instead of SEARCH...didnt work, so I brute-forced it

+ 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 end of string with varying length
    By reedersketer in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-08-2015, 05:16 PM
  2. [SOLVED] Extracting varying length text from the middle of a string
    By tm314159 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 11-20-2014, 07:23 PM
  3. Replies: 4
    Last Post: 08-13-2014, 11:03 PM
  4. Removing various different text, from varying length text strings
    By cloudwalking in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-04-2013, 10:37 AM
  5. Replies: 5
    Last Post: 09-11-2012, 08:40 AM
  6. Text to Column with Text & Varying-length Numbers
    By vtshipe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2011, 07:35 AM
  7. Replies: 6
    Last Post: 10-01-2009, 02:50 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