+ Reply to Thread
Results 1 to 12 of 12

Grab last word from string and then delete word from original string.

  1. #1
    Registered User
    Join Date
    11-26-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    95

    Grab last word from string and then delete word from original string.

    I have several hundred rows of data where I need to find the last word in a String and paste it into the adjacent column then delete the last word from the original string. (Splitting the last word)

    The range will be based on the user selection. The code will then loop through all the rows splitting the last word from the string.

    EXAMPLE
    The Park Gove Dublin

    This would become
    The Park Grove -Next Cell- DUBLIN

    Appreciate any help. Thank you

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,815

    Re: Grab last word from string and then delete word from original string.

    Assuming your data is in column A starting in row 2, try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Grab last word from string and then delete word from original string.

    If you want it to be without VBA then the following will do what you want but (I think this is different to your requirements) place the two split strings into 2 new cells

    ie if your String is in A1

    then in B1
    Please Login or Register  to view this content.
    and in C1
    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  4. #4
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Grab last word from string and then delete word from original string.

    I am trying to solve this problem but found Mumps1 answered really nice.
    1. Thank those who have helped you by clicking the Star * below the post.
    2. Please mark your post [SOLVED] if it has been answered satisfactorily.

    Sincerely,
    Farid

  5. #5
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Grab last word from string and then delete word from original string.

    This is very similar to Mumps' solution but uses the ActiveCell to determine what to update. Anything below the ActiveCell in the same column as the ActiveCell gets updated so giving the user the choice of what data to update.

    Please Login or Register  to view this content.
    Please click *Add Reputation if I've helped

  6. #6
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Grab last word from string and then delete word from original string.

    To do it exactly as youve requested though, you'll need to add a button with the following code:

    Please Login or Register  to view this content.
    The highlight the cells you want to run it on and press the button.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-26-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    95

    Re: Grab last word from string and then delete word from original string.

    pjwhitfield - This code is very handy. However if I click the button twice it clears the new cell with the last word. Whereas the code above keeps stripping out the last word from the string.

  8. #8
    Registered User
    Join Date
    11-26-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    95

    Re: Grab last word from string and then delete word from original string.

    kadeo this works perfect. Are you able to tweak it so it only looks at a selected area instead of the whole column?

  9. #9
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Grab last word from string and then delete word from original string.

    Quote Originally Posted by mtilbury View Post
    ...Are you able to tweak it so it only looks at a selected area instead of the whole column?
    This should do that. As long as you only select data in one column at a time it should work fine.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Grab last word from string and then delete word from original string.

    Quote Originally Posted by mtilbury View Post
    pjwhitfield - This code is very handy. However if I click the button twice it clears the new cell with the last word. Whereas the code above keeps stripping out the last word from the string.
    Ahhh the inclusion of TRIM should resolve that, what was happening is the space before the last word remained on the end of the string so when you run it again it splits on that lonely space and returns nothing, amend
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-26-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    95

    Re: Grab last word from string and then delete word from original string.

    Works great. Thank you

  12. #12
    Registered User
    Join Date
    11-26-2014
    Location
    London
    MS-Off Ver
    2013
    Posts
    95

    Re: Grab last word from string and then delete word from original string.

    pjwhitfield - Thank you this works as well. Thank you. Makes sense about the 'space' being picked up. Thank you

+ 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] Delete rows over and under word in string in cell
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2014, 04:44 AM
  2. Replies: 1
    Last Post: 09-11-2014, 10:59 AM
  3. Replies: 2
    Last Post: 08-05-2013, 04:45 PM
  4. Delete Rows based on Two Criteria (Word(s) String and Date)
    By PaulLor89 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-05-2013, 07:49 PM
  5. find how many times a word appears in a string at certain positions within the string
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-05-2013, 12:05 AM
  6. delete specific word from string
    By karinos57 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-12-2009, 08:28 PM
  7. [SOLVED] How can delete the duplicate word from a string in cell in EXCEL
    By Laxman A Patil in forum Excel General
    Replies: 1
    Last Post: 05-12-2006, 10:10 AM

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