Consulting

Results 1 to 5 of 5

Thread: Sort names NEWBIE

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    27
    Location

    Sort names NEWBIE

    Attached: How can I make a column automatically sort by last name (1st column) that contains first an last name and have D.O.H (3rd column) info stay with the name. A command button would also work for me, just not sure how to do it. Thank you
    Attached Files Attached Files

  2. #2
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    Names are easier to sort if you have one column for First Name and a different column for Last Name.
    (Possible then sort first by Last Name followed by first name)


    Use standard Excel functionality to put values in adjacent columns as follows:
    If Peter Smith is in cell A3
    =LEFT(A3,FIND(" ",A3,1)-1) returns value Peter
    =RIGHT(A3,LEN(A3)-FIND(" ",A3,1)) returns value Smith
    (beware - this works only in cases with one first name)


    If it is not easy to modify worksheet structure, then input the names differently
    Instead of Peter Smith, input as Smith,Peter
    which will allow you to sort by the last name (and will automatically second sort on first name)

    I have had a look at your workbook - column A only contains First Names

  3. #3
    VBAX Regular
    Joined
    May 2015
    Posts
    27
    Location
    Thanks for the help, I made 2 columns, first and last names. How can I have VBA automatically sort the names when names are input. Thanks again

  4. #4
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    I assume you want to sort first by Last Name and then by First Name
    See attached file. Click on the button and see what happens.
    I unmerged cells within data sort range - one of the merged cells was causing a problem
    The macro is called SortBySurname - you will need to adapt to suit your column numbers and range
    Attached Files Attached Files

  5. #5
    VBAX Regular
    Joined
    May 2015
    Posts
    27
    Location
    That's great, works perfect. Thank again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •