+ Reply to Thread
Results 1 to 4 of 4

Remove text between first and last space.

  1. #1
    Registered User
    Join Date
    10-19-2011
    Location
    Norwich, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Remove text between first and last space.

    Hi guys, I'm looking for a formula that will remove the text between the first and last space in a cell e.g. 'Mr Brian M Taylor' becomes 'Mr Taylor' in the cell next to it.

    Ideally I'd like it to work when there's only 1 space as well e.g. 'Mr Taylor' displays as 'Mr Taylor' in the next cell using the same forumla as the first example.


    This is a bit advanced for me (but learning all the time :D) so any help would be fantastic.
    Cheers, James.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Remove text between first and last space.

    Try: =LEFT(A1,FIND(" ",A1))&TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",50)),50))

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

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

  3. #3
    Registered User
    Join Date
    10-19-2011
    Location
    Norwich, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Remove text between first and last space.

    Worked a treat, thank you!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,131

    Re: Remove text between first and last space.

    You might want to check for the case where the cell has no spaces:

    =IF(ISERR(LEFT(A4,FIND(" ",A4))),A4,LEFT(A4,FIND(" ",A4))&TRIM(RIGHT(SUBSTITUTE(A4," ",REPT(" ",50)),50)))

    All credit to Dom for the tricky part.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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