+ Reply to Thread
Results 1 to 5 of 5

Finding the final word in a string

  1. #1
    Registered User
    Join Date
    04-30-2007
    Posts
    2

    Finding the final word in a string

    Hey guys,

    I was wondering if I could ask you kind people for help.

    I have a field containing a full name which contains information like:

    Mr Alan James McLellan
    Mrs S Cowans
    Mrs Elaine Thompson
    Mrs Iain S Duncan
    Mrs J White
    Dr David Jameson
    Miss A L Rankin

    I need to extract the surname of each of these people in another cell but can't for the life of me figure out how. They could have anything up to 4 or 5 middle names so there is no consistency to the number of names.

    I feel that this should be extremely easy but I'm stumped. If anyone has the magic formula or VBA code which I'm missing I would be extremely grateful.

    Thanks
    Iain

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try this link

    http://www.ozgrid.com/VBA/ExtractLastWord.htm

    or

    =RIGHT(TRIM(A1),LEN(TRIM(A1))-SEARCH("^^",SUBSTITUTE(TRIM(A1)," ","^^",LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ","")))))

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    04-30-2007
    Posts
    2
    Absolutely spot on! Thank you kindly. Couldn't have asked for more.



    IainT

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Here's another alternative

    =TRIM(RIGHT(SUBSTITUTE(TRIM(A1)," ",REPT(" ",99)),99))

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Nice one Daddylonglegs

    VBA Noob

+ 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