How do I sort by location within a cell in Excel?

L

Leigh

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
 
D

Don Guillett

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
 
P

Peo Sjoblom

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top