sorting by last name

zcraigs

New Member
Joined
Jul 9, 2010
Messages
5
I am trying to sort a column by last name, but the cells have "first name then last name"

how do I sort by last name?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi

You need to split the names out and then sort by a column just containing the last name eg in an adjacent column use the formula:

=REPLACE(A1,1,FIND(" ",A1&" "),"")

to extract just the last name and then select both original column and this column and sort based on this new formula column.
 
Upvote 0
Great stuff. What would a person do if they also have names with middle intiails, middle names or last names that would have things like Smith-Jones.
 
Upvote 0
Assuming it was structured like this in the name column:

Robert James Harris
Eileen Sue Smith-Jones
John Smith

Then you can get the last name only using:

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))
 
Upvote 0
Great stuff. What would a person do if they also have names with middle intiails, middle names or last names that would have things like Smith-Jones.

I actually saw a custom macro written just for that type of situation. I cannot remember which website I saw it on... but it can certainly be done with a VBA script.

Richard,
That is really kind of neat! What does the 'REPT' function do? (does it stand for repeat?)
 
Upvote 0
Hello Richard,

Thanks so much. If a person wanted to extract the middle name only how would the affect of sometimes three being an initial with or without a period or a full middle name instead?
 
Upvote 0
Hello Richard,

Thanks so much. If a person wanted to extract the middle name only how would the affect of sometimes three being an initial with or without a period or a full middle name instead?

Using a variation of his previous formula, copy & paste this into an empty cell:

=TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),100,100))

The only situation where this will not work is if your workbook contains a list of names that don't have a middle initial. (e.g. John Doe). In such a case, it would treat "Doe" as the middle name - which you don't want. Until Richard replies back to this thread, this is the quickest solution I have for you.
 
Upvote 0
Hello Burrgogo,

Thanks. The list has many variants i.e. some without middle names, initials with or without periods etc.
 
Upvote 0
Hello Burrgogo,

Thanks. The list has many variants i.e. some without middle names, initials with or without periods etc.

The whole premise is sort of odd to me. Who sorts by middle name anyway? In most situations I've come across, people want the list sort either by first or last name - rarely ever the middle name or initial. Is there something additional you need to after the sorting aspect? Can you give us more details?


At any rate, the function I gave you above will work regardless of whether the middle name (or initial) has a period. In your case, since the list contains a mixed bag of names with & without middle names, I think the best course is to use a VBA script.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top