+ Reply to Thread
Results 1 to 8 of 8

Extract Text After Second To Last Comma in A Text String

  1. #1
    Registered User
    Join Date
    01-05-2016
    Location
    Texas, USA
    MS-Off Ver
    Office 365
    Posts
    13

    Extract Text After Second To Last Comma in A Text String

    Hello, I have the following text string and I need to see how I can keep the text AFTER the second to Last Comma.

    I have:
    12/08/2015 15:36 EL PASO, TX 79906, 12/12/2015 14:12 HERMOSILLO, SON 83000

    I want to keep:
    12/12/2015 14:12 HERMOSILLO, SON 83000

    I have been using a RIGHT function but since the length of the text string varies, I have to go in manually and clean it up. Need to know if there is an easier way. I have seen how you do it to the LEFT of a comma but not to the RIGHT. Thanks for your help!

  2. #2
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: Extract Text After Second To Last Comma in A Text String

    Try this:

    Please Login or Register  to view this content.
    I put the string in A1

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Extract Text After Second To Last Comma in A Text String

    Try this

    =TRIM(MID(A1, SEARCH("^",SUBSTITUTE(A1,",","^", LEN(A1)-LEN(SUBSTITUTE(A1,",",""))-1))+1,9999))

    This
    SUBSTITUTE(A1,",","^", LEN(A1)-LEN(SUBSTITUTE(A1,",",""))-1)
    will replace the next to last comma (no matter how many comma's exist) with a "^". The rest finds that ^ and takes everything to the right of it.
    Last edited by ChemistB; 01-05-2016 at 01:59 PM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    01-05-2016
    Location
    Texas, USA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Extract Text After Second To Last Comma in A Text String

    Thank you Gatti, it works for that example but I have multiple sets of data and they vary all the time, Here is one of the most complex strings. It did not work with this one.

    12/04/2015 15:50 Celaya, GTO 38110, 12/07/2015 11:30 EL COLORADO, QRO 76246, 12/17/2015 10:55 LAREDO, TX 78045, 12/17/2015 14:26 LAREDO, TX 78045, 12/17/2015 22:06 LAREDO, TX , 12/18/2015 21:49 DALLAS, TX

    I want to keep which is the data after the second to last comma:
    12/18/2015 21:49 DALLAS, TX

    Can you help with this? Thanks.

  5. #5
    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: Extract Text After Second To Last Comma in A Text String

    Try this

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    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

  6. #6
    Registered User
    Join Date
    01-05-2016
    Location
    Texas, USA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Extract Text After Second To Last Comma in A Text String

    Thank you ChemistB!! That worked great! Just saved me a ton of time!!

    Thanks for all your help everyone.

  7. #7
    Registered User
    Join Date
    01-05-2016
    Location
    Texas, USA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Extract Text After Second To Last Comma in A Text String

    That worked as well AlKey. Thanks Again!!

  8. #8
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Extract Text After Second To Last Comma in A Text String

    Glad to help

+ 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] How to extract words from a text string separated by comma
    By shukla.ankur281190 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-22-2015, 04:16 AM
  2. Extract text between two characters in a string - varing text length
    By luv2birdie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-04-2014, 06:10 PM
  3. [SOLVED] Extract text from a given point in a text string, when data points do not share the given
    By reedersketer in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-09-2014, 03:57 PM
  4. [SOLVED] How to extract text strings out of longer text string
    By GIS2013 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-17-2013, 06:08 AM
  5. [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
  6. Extract postcode after last comma in text string
    By TheRobsterUK in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-15-2013, 09:35 AM
  7. EXTRACT TEXT FROM TEXT STRING:The names are of variable length
    By carricka in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-08-2005, 06:05 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