Ask Experts Questions for FREE Help !
Ask
    ukchemist's Avatar
    ukchemist Posts: 1, Reputation: 1
    New Member
     
    #1

    Nov 24, 2008, 12:39 PM
    Excel: extract surname from column with first name and sometimes initials
    In an Excel spreadsheet I have a column containing first name, sometimes an initial (or two), then a surname then in brackets a date of birth. How can I extract the surname?

    e.g. one row might be John A Smith (01/01/1990)
    The next might be John A Smith (02/02/1991) and the next
    John Smith (03/03/1992)

    All help very gratefully received
    ebaines's Avatar
    ebaines Posts: 12,131, Reputation: 1307
    Expert
     
    #2

    Nov 24, 2008, 02:16 PM

    The following assumes that's there's a maximum to the number of words that can make up a name (i.e. never more than 4), and that you don't need to worry about suffixes like "Jr" coming after the last name. Starting with a string in cell A1:

    1. First, strip off the date string at the end - (i.e, a string starts with a spce and left parenthesis) and put this in cell A2:

    =LEFT(A1,SEARCH(" (",A1)-1)

    You now have the name by itself.

    2. Now we're going to count how many spaces there are in the string in cell A2,and put this value in A3:

    =IF(LEN(TRIM(A2))=0,0,LEN(TRIM(A2))-LEN(SUBSTITUTE(A2," ","")))

    3. If this number in A3 is >0, then search for the first instance of a space in the string in A2, strip off the leading word and storewhatever is to the right of that in cell A4:

    =RIGHT(a2,LEN(a2)-IF(a3>0,SEARCH(")))

    3. If this number in A3 is >0, then search for the first instance of a space in the string in A2, strip off the leading word and storewhatever is to the right of that in cell A4:

    =RIGHT(a2,LEN(a2)-IF(a3>0,SEARCH(",a2),0))

    Repeat steps 2 and 3 four times, changing references to cells A2 and A3 to cells A4and A5, etc. As long as there aren't more than 4 words in any name, you'll end up with just the last name in cell A12.

    You could probably combine all this into one massive command. Hope this helps.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Excel 15 digit issue, tried converting to text, text to column feature negates fix [ 6 Answers ]

I have the following numbers that exceed 15 characters that needs to be split into its own columns. Down the road, there would be thousands of such rows of data with the first couple set of unique numbers. 890432453253208820,5004500558,05CC,1,0,0,0,0,0,0, 0000,5.0000,2007-01-11...

Sorting by surname on excel [ 9 Answers ]

How do I sort data by surname on excel? I have office 2007

How can I sort data on a Hidden column in Excel? [ 2 Answers ]

I have a spreadsheet that has a pivot table in it. Each record has a time group column and a time nbr column in the pivot table. (i.e. Timegroup = 90 days before and a timenbr of 1 is assigned to this group, Timegroup = 60 days before and a timenbr of 2 is assigned to this group,...

Excel 07 - Pressing enter won't bring me to the A column [ 4 Answers ]

I'm new to excel and learning it at my local college but am stuck with a small problem. say I enter info in A2, then B2... and so on until I get to say... E2. If I hit enter after inputting info into E2 my next active cell is random. its going between all the letters in the next row down,...

Column Protect in excel [ 1 Answers ]

How to protect the column in excel??


View more questions Search