+ Reply to Thread
Results 1 to 6 of 6

Formula for sorting column by last name

  1. #1
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Question Formula for sorting column by last name

    Cells have entries like this: First name, space, last name, city. E.g. John Doe, Chicago.

    I wish to sort the column by the last name.

    Is there a formula for this?

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,859

    Re: Formula for sorting column by last name

    Assume your data in Column A. In column B, (a helper column), insert the following and copy it down.

    =MID(A1,FIND(" ",A1),FIND(",",A1)-FIND(" ",A1))

    Then sort on the Column B
    Last edited by alansidman; 12-08-2016 at 11:59 PM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Formula for sorting column by last name

    Perfect!

    Just one more question...

    Assume there are other names like "Mary Elizabeth Smith, Chicago". In such cases, it would be better to use a formula which picks up the word preceding the last word. Could you please give such a formula?

  4. #4
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Formula for sorting column by last name

    Found two of them elsewhere:

    =TRIM(LEFT(RIGHT(SUBSTITUTE(" "&TRIM(A1)," ",REPT(" ",40)),80),40))

    OR

    =MID(A1,FIND("^",SUBSTITUTE(A1," ","^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))+1,FIND("^",SUBSTITUTE(A1," ","^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))-FIND("^",SUBSTITUTE(A1," ","^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))-1)

    However, they take the word and include the comma. E.g. Smith,

    Any suggestions to rectify this issue? Or, a better formula perhaps?

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula for sorting column by last name

    Quote Originally Posted by Bradex View Post
    Found two of them elsewhere:

    =TRIM(LEFT(RIGHT(SUBSTITUTE(" "&TRIM(A1)," ",REPT(" ",40)),80),40))

    OR

    =MID(A1,FIND("^",SUBSTITUTE(A1," ","^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))+1,FIND("^",SUBSTITUTE(A1," ","^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))-FIND("^",SUBSTITUTE(A1," ","^",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))-1)

    However, they take the word and include the comma. E.g. Smith,

    Any suggestions to rectify this issue? Or, a better formula perhaps?
    I would not recommend to use the above formulas because they will fail if the the city contains more than one word; San Francisco, or Fort Lauderdale.

    Use this one instead:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1 John Doe, Chicago Doe
    2 Mary Elizabeth Smith, Chicago Smith
    3 Mary J Dougan, San Francisco Dougan
    4 George H Bush, Dallas Bush
    5 George H W Bush, Fort Lauderdale Bush
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  6. #6
    Registered User
    Join Date
    03-28-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    38

    Re: Formula for sorting column by last name

    That's perfect! Thanks a lot AlKey!

    Could you also explain what this formula does in plain words.

+ 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] Sorting first column not working, sorting column 2 and 3 does (same code)
    By jokris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2016, 03:08 AM
  2. Replies: 0
    Last Post: 10-28-2014, 03:09 PM
  3. [SOLVED] Formula to Rank the number of times a word appears in a column dynamic with Sorting
    By caliskier in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-02-2014, 04:26 PM
  4. Sorting a range to invert it upside down without sorting by any specific column
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-29-2013, 12:53 PM
  5. Sorting a column by age, formula help needed...
    By amster in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-26-2013, 03:59 PM
  6. [SOLVED] Sorting text column that contains a formula
    By cara13xxi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-25-2012, 05:29 PM
  7. Sorting using a column that contains formula
    By lsbcal in forum Excel General
    Replies: 2
    Last Post: 09-12-2011, 12:14 PM

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