ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I sort by location within a cell in Excel? (https://www.excelbanter.com/excel-discussion-misc-queries/164943-how-do-i-sort-location-within-cell-excel.html)

Leigh

How do I sort by location within a cell in Excel?
 
I am trying to sort a list alphabetically but position within a cell. For
example, my cells contain: John Smith, Will Jones, Gary Roberts. I want to
sort by the last item in the cell. Thanks

Don Guillett

How do I sort by location within a cell in Excel?
 
Something like this to create a column you can sort by.

Sub sortbylast()
For Each c In Range("f2:f7")
c.Offset(, 1) = Right(c, Len(c) - InStrRev(c, " "))
Next
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Leigh" wrote in message
...
I am trying to sort a list alphabetically but position within a cell. For
example, my cells contain: John Smith, Will Jones, Gary Roberts. I want
to
sort by the last item in the cell. Thanks



Peo Sjoblom

How do I sort by location within a cell in Excel?
 
You would need a help column with the last names, then sort on the help
column.

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


copy down in a help column will give you the last names unless they use
things like JR etc

then you can sort on that help column



--


Regards,


Peo Sjoblom


"Leigh" wrote in message
...
I am trying to sort a list alphabetically but position within a cell. For
example, my cells contain: John Smith, Will Jones, Gary Roberts. I want
to
sort by the last item in the cell. Thanks





All times are GMT +1. The time now is 01:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com