+ Reply to Thread
Results 1 to 6 of 6

How to get last name from A Column to copy to B column

  1. #1
    Registered User
    Join Date
    09-23-2007
    Posts
    2

    How to get last name from A Column to copy to B column

    Abraham Lincoln Lincoln
    Alexander Hamilton Hamilton
    George Washington Washington

    I have a list of first and last name in column A. But I need to sort them alphabetically by last name. My best idea was to copy the last name into another column and sort alphabetically by that column. How can I automate this using a Macro or VBA? I'm a student at UCF with medium knowledge of Excel.

  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
    Maybe this UDF

    Enter this in a module

    http://www.contextures.com/xlvba01.html#Regular

    Please Login or Register  to view this content.
    then this in B1 and drag down
    =lastword(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
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello rd12345,

    Here is a macro that will separate the last names and place them in column "B". The names are then sorted in A to Z order. Run the macro by using ALT+F8 to display the Macro Dialog List and select SortByLastName
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Right Click on any Sheet's tab
    4. Left Click on View Code in the pop up menu
    5. Press the keys ALT+I to activate the Insert menu
    6. Press M to insert a Standard Module
    7. Paste the code by pressing the keys CTRL+V
    8. Make any custom changes you need to the macro
    9. Save the Macro by pressing the keys CTRL+S

    Sincerely,
    Leith Ross

  4. #4
    Registered User
    Join Date
    09-23-2007
    Posts
    2
    Yes, Elvis is alive! Your idea worked. You are a lifesaver. You have saved me so much time. Thanks a million

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    without going down the vba macro route for names in the format
    xxxxx yyyyyy in column a, try in b1 =MID(A1,(FIND(" ",A1)+1),50)
    if the surname is longer than 50 letters i'll eat my hat!

  6. #6
    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
    But with this format it would be

    =RIGHT(A1,LEN(A1)-FIND(" ",A1,FIND(" ",A1,1)+1))

    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