+ Reply to Thread
Results 1 to 7 of 7

How to extract 3 last words from an excel cell using a predefined delimiter?

  1. #1
    Registered User
    Join Date
    03-25-2012
    Location
    Tehran
    MS-Off Ver
    Excel 2010
    Posts
    3

    How to extract 3 last words from an excel cell using a predefined delimiter?

    Hello Everyone,

    Does anyone knows a formula to extract last three words of my data as displayed below:


    Tahvili Sq., 17th St., No. 403,, Shiraz, Fars, IR
    No. 31, Jafar Gholi Alley,West Nostrat,Tohid Sq.,Tehran,Tehran, IR
    22 No - 2 West St - Seol St tehran, IR1995934733, IR
    Qazi Asadollah Sq., No. 6, 1st Floor,, Kashan, Isfahan, IR
    No 63, Abdoos Alley, Vaziri St,Tehran,Tehran, IR
    No. 48, Shahid Mohsen Kashfi St., Beginning Of Shahid Madani Ave., Resalat Sq.Tehran, IR1634957514, IR
    Faramarz Abbasi Sq., Baharan St., 7th Fajr Alley, No. 139,, Mashhad, Khorasan Razavi, IR
    Javanh Blindalley,The Fifth,St Shikh Safi, Esfahan, Esfahan, IR
    No. 11, East 15, South Shaghayegh, Ferdows Blvd., Sadeghieh Sq.,Tehran, IR1484983664, IR
    Arghavan St - No 4, Esfahan, Esfahan, IR
    Unit 2 .No 58 .Milad Cr.Azadshahr, Mashhad, Khorasan Razavi, IR
    Mehrshahr, Eram Blvd., Milade 4 St., No.58,, Karaj,Tehran, IR
    #48,2nd Fl.,Masoud Bazar,Zand Blvd., Shiraz, Fars, IR
    Molla Sadra Ave. At Sheikh Bahai, Setade Farmandehi Sazemane Atashneshani Tehran, IR14358-63151, IR
    Nabshe Meidane Shahid Mosavi Ghochani, Mashhad, Khorasan Razavai, IR
    4th Floor, Khayyam Building, Moallem St.,, Rasht, Guilan, IR
    No. 20, Sadoughi Blvd..Yazd, IR89197, IR
    Khiaban Talaghani , Nabshe Khiaban Sepahbod Gharani Tehran, IR1581795411, IR
    No. 51, West 188 St.,Tehranpars,,Tehran,Tehran, IR
    No.7, Mirzaee Alley, Mojahedin St.,Tehran, IR11577, IR
    Tehranmunicipality(1888) No.59 , Ansari Alley , Behesht St , Parkeshahr ,,Tehran,Tehran, IR
    No. 27, 32th Gharani, Gharani Blvd.,, Mashhad, Khorasan Razavi, IR
    No 25, Secend Laleh Alley, Mojahed Kabir Street, Laleh Sharghi Street, Jannat Abad,Tehran,Tehran, IR



    I want them to be extracted like this:

    Shiraz, Fars, IR
    Tehran,Tehran, IR
    tehran, IR1995934733, IR
    Kashan, Isfahan, IR
    Tehran,Tehran, IR
    Tehran, IR1634957514, IR
    Mashhad, Khorasan Razavi, IR
    Esfahan, Esfahan, IR
    Tehran, IR1484983664, IR
    Esfahan, Esfahan, IR
    Mashhad, Khorasan Razavi, IR
    Karaj,Tehran, IR
    Shiraz, Fars, IR
    Tehran, IR14358-63151, IR
    Mashhad, Khorasan Razavai, IR
    Rasht, Guilan, IR
    Yazd, IR89197, IR
    Tehran, IR1581795411, IR
    Tehran,Tehran, IR
    Tehran, IR11577, IR
    Tehran,Tehran, IR
    Mashhad, Khorasan Razavi, IR
    Tehran,Tehran, IR



    As you see the delimiter is not always the same prior to third word to the last; it might be sometimes a comma, dot or even a space.

    And sometimes the second word itself consist of two or more words with spaces in between them. The red color represent those cells.

    And sometimes the second word itself consist of alphanumeric characters with a hyphen between them. The blue color represent those cells.

    Your help is highly appreciated, guys.


    Thanks,
    Vaalf
    Last edited by vaalf; 03-25-2012 at 01:29 PM.

  2. #2
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: How to extract 3 last words from an excel cell using a predefined delimiter?

    Hi

    this formula has a couple (maybe more) of limits: it cannot split correctly the string if comma is not present as delimiter (third string in your example) and often it adds too many "," to the output because it substiutes blank spaces into commas (again as in the third address in your example.


    Please Login or Register  to view this content.
    Anyway I hope it's a little help

    Regards
    Attached Files Attached Files
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon ("Add Reputation") below the post.

    Please, mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How to extract 3 last words from an excel cell using a predefined delimiter?

    i can nearly do it but those KhorasanRazavai mess thinks up
    however i split it with text to columns delimited with comma ,space, and full stop(period) in the other box
    then use formulas to pull the last 3 cells
    Attached Files Attached Files
    "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

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: How to extract 3 last words from an excel cell using a predefined delimiter?

    Hi

    With your data in A1, give a try to this.

    =TRIM(RIGHT(SUBSTITUTE(A1;" ";REPT(" ";60));180))
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  5. #5
    Registered User
    Join Date
    03-25-2012
    Location
    Tehran
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to extract 3 last words from an excel cell using a predefined delimiter?

    Quote Originally Posted by Fotis1991 View Post
    Hi

    With your data in A1, give a try to this.

    =TRIM(RIGHT(SUBSTITUTE(A1;" ";REPT(" ";60));180))
    Hi,

    Thanks for posting a formula but it contains errors! could you check it out please?

    Thanks,
    vaalf

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How to extract 3 last words from an excel cell using a predefined delimiter?

    =trim(right(substitute(a1," ",rept(" ",60)),180))

  7. #7
    Registered User
    Join Date
    03-25-2012
    Location
    Tehran
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to extract 3 last words from an excel cell using a predefined delimiter?

    Quote Originally Posted by martindwilson View Post
    =trim(right(substitute(a1," ",rept(" ",60)),180))
    Martin,

    Thanks for your help. Your formula was the solution. My great thanks!

    Thanks,
    Vaalf

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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