+ Reply to Thread
Results 1 to 19 of 19

Sorting names by Surname Alphabetically without using two columns

  1. #1
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Sorting names by Surname Alphabetically without using two columns

    I've been looking online for a solution to sorting names alphabetically using the surname but all the solutions come via using two columns, one for the first name, one for the surname. I wanted to avoid that as when published to a webpage it is not very attractive. At the moment I have the names listed Adams. Brian, Adams. Linda, Brown, Dave, etc because they normally are used alphabetically but sometimes when you are doing result tables the names move up and down. I would however like to exhibit the names as Brian Adams, Linda Adams, Dave Brown, etc because I think they are aesthetically better. Especially when in a pair or a team. Brian Adams & Dave Brown looks so much better than Adams. Brian & Brown. Dave. Anyway the solution I came up with is to number the names Alphabetically in a hidden preceding column and then when sorting by say points, highest points first, then the number column representing the name. This works, but I just wondered if there were a better way to go. For a start the If statement would be very long if you had 50 names, one of my charts has 150. I currently have =IFS(I7=1,$G$7,I7=2,$G$8,I7=3,$G$9) and that's just for 3 names. Maybe the solution is the right way to go but there is a better formula to use or there is a better solution altogether?

    I've attached a workbook as an example, in case you can't picture what I'm asking. Example 4 is the solution, sorting by K and then I. I'd use VBA to update each time data was added.

    Thank you.
    Attached Files Attached Files
    Last edited by Marvo; 03-26-2024 at 08:09 AM.

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.96 for Mac MS 365
    Posts
    8,697

    Re: Sorting names by Surname Alphabetically without using two columns

    I'm having difficulty making out your sort order. this... =TRIM(RIGHT(B7,LEN(B7)-FIND(".",B7))&" "&LEFT(B7,FIND(".",B7)-1)) gets rid of the . between last name and first and rearranges them to first name and last name. Sorting however becomes a different issue. Initially it appears (col J) that your sort is alphabetical by first name descending since last name Pym would be above McKenzie in a descending order. But in a descending order Brian would be above Benjamin but you have them reversed which makes it appear that if they begin with the same letter for the first name then you want the last name to take precedence?
    This formula =SORT(G7:G9,,-1,FALSE) should produce what you want except that Ben and Brian are reversed. Maybe you need to clarify what your sort order rules are a bit more.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    The sort order would be points total, then alphabetically by surname. So if no points has been awarded so far, the names would show alphabetically, Adams, McKenzie, Pym. Then if McKenzie got 10 points it would go to McKenzie, Adams, Pym. Then if Pym got 5 points it would go McKenzie, Pym, Adams.

    Thanks for responding.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: Sorting names by Surname Alphabetically without using two columns

    YOu can sort the names like this:

    =LET(s,LEFT(B7:B9,FIND(".",B7:B9)-1),f,MID(B7:B9,FIND(".",B7:B9)+1,99),SORTBY(TRIM(f&" "&s),s,1,f,1))

    I am unclear as to which column contains the points and how they are derived.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: Sorting names by Surname Alphabetically without using two columns

    This will do the whole lot:

    =LET(a,B7:C9,s,LEFT(B7:B9,FIND(".",B7:B9)-1),f,MID(B7:B9,FIND(".",B7:B9)+1,99),p,C7:C9,x,SORT(p,,-1),y,SORTBY(TRIM(f&" "&s),p,-1,s,1,f,1),CHOOSE({1,2},y,x))

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    B
    C
    D
    E
    F
    6
    Name Points
    7
    Adams. Brian
    10
    Ian McKenzie
    30
    8
    McKenzie. Ian
    30
    Benjamin Pym
    20
    9
    Pym.Benjamin
    20
    Brian Adams
    10
    Sheet: Sheet1
    Attached Files Attached Files

  6. #6
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    I've several list of names Ali, several tables, all sorted for different things, points, money, etc. In my largest table with 150 names (and growing) Column B has the names, Column Q has total prize money. the Names start in ROW 3 and finish in ROW 152. Total table is A1 to Q152, though A can be ignored because its static, just goes 1st, 2nd, 3rd, etc.

    I just think when transferred to our website the names look much more pleasing to the eye if they presented Benjamin Pym rather than Pym. Benjamin.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: Sorting names by Surname Alphabetically without using two columns

    Oh, dear ... How many times do we have to ask you to provide realistic sample data??? It's SOOOOO frustrating when you come back with a response like that!

    Did you look at the solution offered in post #5?

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: Sorting names by Surname Alphabetically without using two columns

    I've replicated the formula to match the data layout described:

    =LET(s,LEFT(B3:B5,FIND(".",B3:B5)-1),f,MID(B3:B5,FIND(".",B3:B5)+1,99),p,Q3:Q5,x,SORT(p,,-1),y,SORTBY(TRIM(f&" "&s),p,-1,s,1,f,1),CHOOSE({1,2},y,x))

    Just adapt the length of the B and Q ranges to suit:

    =LET(s,LEFT(B3:B152,FIND(".",B3:B152)-1),f,MID(B3:B152,FIND(".",B3:B152)+1,99),p,Q3:Q152,x,SORT(p,,-1),y,SORTBY(TRIM(f&" "&s),p,-1,s,1,f,1),CHOOSE({1,2},y,x))
    Attached Files Attached Files
    Last edited by AliGW; 03-26-2024 at 05:55 AM.

  9. #9
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    Thank you, I'll get on to it.

    Sorry about the example but sometimes the stuff I have is personal and private, names, age, address, shirt size, email, account No, money, etc, I don't think I have the right to publicise without permission, hence a simple mock-up. This was I thought a simple question, I'd look at many videos on utube to find a solution but they all resorted in having the names in separate columns. I'm sure your solution will work just fine, I'll mark the thread as solved once I've tested it on one of my sheets. Thank you.

    My website for the golf stuff is here

    https://ma3075.wixsite.com/midshires

    Lots on there.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: Sorting names by Surname Alphabetically without using two columns

    Marvo - all you have to do is REMOVE the sensitve stuff, but leave the columns where they are. It really isn't hard.

    Once again - have you looked at my solutions, or am I, for want of a better expression, pissing into the wind???

    I don't need to see your website, thanks - I need you to focus on this thread.

    PS I just looked - I used to do web design ...

    PPS I see you ARE looking at my suggestion - good. Let me know how you get on.
    Last edited by AliGW; 03-26-2024 at 06:04 AM.

  11. #11
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    I'm sorry, I'm not very well today, got some sort of bug. Disappointing, first time I've been ill since taking the first Covid jab. I'm starting now.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: Sorting names by Surname Alphabetically without using two columns

    Oh, I'm sorry to hear this. Get well soon!

    I haven't been ill since I retired from teaching - hotbeds of nasties, schools!

  13. #13
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    Okay, your solution is very good, it rights the names the correct way. However I obviously haven't been clear, that's not what I'm after. What I want to do is physically change the names myself, (find and replace) means I can do each name just once. When that's done, I'll be left with the names as I want them for display purposes, its then I'll need to sort them alphabetically. That was when I kept finding solutions but all using two cells, which I didn't want to do, again for display purposes.

    I came up with the original solution where you have a number designated to a list and when you put a number in A1, a name will appear in B1. So "Adams. Brian" in the list is No1 (Alphabetically), I change that manually to Brian Adams but retain the No 1. I can then sort Alphabetically using 1 to 150. It would still be two columns but one would be hidden, so just the name showing.

    Anyway, I've put another sheet in the example (as it is) with, first, what I've got (sorted by Q, then B) and second, what I want (Q then maybe my own Helper R which would be the names numbered alphabetically by surname). What do you reckon?

    Apologies for leading you down the wrong path again, it all makes sense in my mind.
    Attached Files Attached Files

  14. #14
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Sorting names by Surname Alphabetically without using two columns

    Totally lost. What do you expect to see? Where do you expect to see it?
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,234

    Re: Sorting names by Surname Alphabetically without using two columns

    Maybe this?

    =LET(f,LEFT(B15:B22,FIND(" ",B15:B22)-1),s,MID(B15:B22,FIND(" ",B15:B22)+1,99),SORTBY(CHOOSE({1,2},B15:B22,Q15:Q22),Q15:Q22,-1,s,1,f,1))

    Really confusing ...

    Heading into the garden now.
    Attached Files Attached Files

  16. #16
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    The first box A1:Q10 is how it is.

    The second box A13:Q22 is how I want it.

    Note: The actual list is 150 names long and prize money is added to it every 3 weeks.

  17. #17
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,427

    Re: Sorting names by Surname Alphabetically without using two columns

    I'm a bit confused as well, but can't you just use this formula in B15:

    =TRIM(RIGHT(B3,LEN(B3)-FIND(".",B3))&" "&PROPER(LEFT(B3,FIND(".",B3)-1)))

    then copy it down? The other data could then be copied down also (not sure where that comes from).

    Hope this helps.

    Pete

  18. #18
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    I tell you what guys, don't worry about it, I can't seem able to explain what I want. I'll mark it as SOLVED and then everybody can move on. Thanks for the help.

  19. #19
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    1,010

    Re: Sorting names by Surname Alphabetically without using two columns

    I managed to do what I set out to do, the two tables on All-time attendances records and Prize winners now sort automatically, first by total points total, then alphabetically using the surname using a helper column adjacent to the Totals Columns. I created a new sheet "List" for the master table which all others will refer to. The good news is when you add a new name the numbers change automatically throughout the spread sheet. That was always a chore.

    Anyway I've attached the workbook in case anybody in future wants to know how to sort alphabetically when the names are in one cell the wrong way round (first name first).

    Can you imagine what I could achieve if I had the slightest inkling of what I'm was doing?

    Over and out for the time being.
    Attached Files Attached Files

+ 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 data alphabetically in one cell by surname
    By Jasper1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-14-2020, 04:30 AM
  2. [SOLVED] Sorting column alphabetically by surname
    By Nemery in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-17-2017, 12:22 PM
  3. Sorting array of file names alphabetically
    By mimino in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-16-2013, 10:09 AM
  4. Sorting multiple columns alphabetically
    By PJ25 in forum Excel General
    Replies: 8
    Last Post: 05-06-2013, 12:22 AM
  5. Sorting related columns alphabetically
    By chef.ivan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2010, 05:28 AM
  6. Sorting multiple columns as 1 list alphabetically?
    By philpott in forum Excel General
    Replies: 4
    Last Post: 10-19-2005, 02:05 PM
  7. Replies: 3
    Last Post: 05-11-2005, 04:06 PM

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