technology made simple.

Splitting LASTNAME,FIRSTNAME columns in Excel

May 14th, 2008 Posted in tech tips

Too often, office workers have to manipulate improperly structured data that comes from mega-systems. For example, if a person wanted to do a mail merge intro line, stating, “Dear <firstname>” but the name field held LASTNAME,FIRSTNAME, they would have a hard time, but here’s a way to handle it using an excel formula that pulls it apart and displays the correct name in title case. I haven’t really tested it with special names including extra things like sir or esquire, but it works pretty good for most names.

Assuming cell A1 holds a name like THORP,TIMOTHY – this formula will result in Timothy Thorp

=PROPER(CONCATENATE(TRIM(RIGHT(A1, LEN(A1)- FIND(",",A1,1))), " ", LEFT(A1,FIND(",",A1,1)-1)))

Explanation of each function in the order that it is processed:

LEN() counts the number of characters in the name (in this example, 13)

FIND() returns the character position of the comma (in this example, 6)

RIGHT() returns the calculated number of characters to the right of the comma (in this example, chars 7-13 or TIMOTHY)

LEFT() returns all of the characters from the beginning of the name up to the comma (in this example, characters 1-5 or THORP)

TRIM() removes extra blank spaces around the comma in case they are present

CONCATENATE() squishes the first and last name into one column together

PROPER() puts the name in title case (first letter of each word capitalized)

From there, you can use the fill handle to copy the formula down the column and Excel Text to Columns and/or paste special to separate things out as you need.

To get the first name by itself :

=PROPER(TRIM(RIGHT(A1, LEN(A1)- FIND(",",A1,1))))

To get the last name by itself:

=PROPER(LEFT(A1,FIND(",",A1,1)-1))

  1. One Response to “Splitting LASTNAME,FIRSTNAME columns in Excel”

  2. By Micah on Dec 8, 2008

    Tim, I really appreciate you sharing very useful information in a succinct and easy-to-understand format. I was able to solve some problems in minutes that would have taken me hours if I hadn’t utilized your code. Thank you!

Post a Comment