+ Reply to Thread
Results 1 to 7 of 7

I want to delete the last two words in a string

  1. #1
    Registered User
    Join Date
    03-23-2016
    Location
    jakarta
    MS-Off Ver
    2010
    Posts
    33

    I want to delete the last two words in a string

    Please help formula for change:

    The original below:

    Modern workshop Yokohama JP
    Lazada.co.id 454542145 US
    Tickt** 14511451 ID
    agoda.com london UK

    I need string be deleted for the last 2 word like below:

    Modern workshop
    Lazada.co.id
    Tickt**
    Agoda.com

    Thanks for attention.

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: I want to delete the last two words in a string

    on first glance
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    but this is very long. Maybe someone else will give you shorter version

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

    Re: I want to delete the last two words in a string

    Hi muharom.habib,

    Here is a method to do this. I assume "words" are separated by spaces.

    You first replace each space with 100 spaces in the string. Then take the last 200 characters in the string and TRIM it. This will leave the last two words.

    I can't tell from your example above what the string is, but the above is how I would do this problem. *To replace each space with 100 spaces use the Substitute function and Rept function.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

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

    Re: I want to delete the last two words in a string

    Maybe this...

    Data Range
    A
    B
    1
    2
    Modern workshop Yokohama JP
    Modern workshop
    3
    Lazada.co.id 454542145 US
    Lazada.co.id
    4
    Tickt** 14511451 ID
    Tickt**
    5
    agoda.com london UK
    agoda.com
    6
    Jazzy
    Jazzy
    7
    8
    Five Four Three Two One
    Five Four Three
    9


    This formula entered in B2 and copied down:

    =SUBSTITUTE(A2," "&TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",50)),100)),"")
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,369

    Re: I want to delete the last two words in a string

    Another option

    =LEFT(A1,FIND("^^",SUBSTITUTE(A1," ","^^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))-1)

  6. #6
    Registered User
    Join Date
    03-23-2016
    Location
    jakarta
    MS-Off Ver
    2010
    Posts
    33

    Re: I want to delete the last two words in a string

    It does not work when some string more than 7 or more words.

    Any other idea to find except using rept fuction?

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

    Re: I want to delete the last two words in a string

    Quote Originally Posted by muharom.habib View Post
    It does not work when some string more than 7 or more words.
    Works for me...

    Data Range
    A
    B
    1
    1 2 3 4 5 6 7 8 9 10
    1 2 3 4 5 6 7 8
    2
    AA BB CC DD EE FF GG HH II
    AA BB CC DD EE FF GG
    3
    One Two Three Four Five Six Seven Eight Nine Ten
    One Two Three Four Five Six Seven Eight

    This formula entered in B1 and copied down:

    =SUBSTITUTE(A1," "&TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",50)),100)),"")

+ 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. Replies: 4
    Last Post: 10-25-2016, 04:45 PM
  2. [SOLVED] Extract 5th string onwards but exclude 6th string onwards if found a specificlist of words
    By suchetherrah in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-07-2016, 03:48 AM
  3. Replies: 15
    Last Post: 10-12-2014, 08:53 AM
  4. [SOLVED] Extract all the words from a string for processing, while leaving string intact.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-10-2014, 02:02 PM
  5. Replies: 1
    Last Post: 07-02-2014, 12:02 PM
  6. Delete words within phrase from list of words
    By El Cosmos in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-04-2014, 02:18 PM
  7. Replies: 3
    Last Post: 11-28-2012, 04:00 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