Excel Basics: Separating First and Last Names in One Cell

Excel Basics: Separating First and Last Names in One Cell

By Bob Umlas, Excel MVP

Here in my first blog post, I’m going to show you how to separate first and last names in one cell using Excel. Imagine you have this worksheet, where the name is in column A:

excel-1

 

 

 

 

 

 

 

 

 

 

 

 

Your job is to separate the first and last names so you wind up with this:

excel-2

 

 

 

 

 

 

 

 

 

 

 

 

 
Then you can delete column A.

The 3 ways I’m going to explain here are:

  1. Formulas
  2. Text-to-Columns
  3. Flash Fill (For Excel 2013 or later)

The formula way is the most difficult, but also perhaps most instructive. To do this, I’ll describe the use of some built-in functions, namely FIND, LEFT, and MID.

Let’s also assume that we know the format is always last name, comma, and first name. Let’s look at cell A2 in detail. If we know the position of the comma, we can determine the location of the first name (the last name always begins the cell).

The FIND function does this job. The syntax (rule) is =FIND(what you’re looking for, in what string): If we put this formula in cell B2: =FIND(“,”,A2), we’ll see 6:

excel-3

 

 

 

This is because the comma is in the 6th position of “Jones, Bob”.

Since the comma is always followed by a space, we then know that the first name is 2 characters after the comma. The MID function takes characters from the “middle” of a string of characters, and the syntax is =MID(cell,start,length). So if in cell C2 we put =MID(A2,B2+2,255), we’ll see this:

excel-4

 

 

 

Notice that we added 2 to the value in B2. The 255 is arbitrary, but certainly large enough for the largest first name, and also the maximum number allowed in the MID function!

We can combine these last 2 cells’ solution into 1. Instead of using B2, we can put what’s in B2 (the FIND function) and substitute it:

excel-5

 

 

 

So we are no longer using cell B2! We can delete column B:

excel-6

 

 

 

OK, now we need the last name, and put it in cell C2. We know that we want all the characters to the left of the comma. That’s =FIND(“,”,A2)-1. Note the “-1”. We don’t want to include the comma. This is where we need to use the LEFT function. It takes this syntax: =LEFT(cell,length). Well, we know the length is that FIND function with the -1:

excel-7

 

 

 

Practically done! Select cells B2:C2, and double-click the fill handle (that’s the cursor when it sits on top of the little square at the bottom right of the selection):

excel-8

 

 

It will copy that formula down to the bottom:

excel-9

 

 

 

 

 

 

 

 

 

 

 

 

 

 

OK, we’re ready for the 2nd technique, Text-to-Columns.

First you select the names in A (from A2:A24), then invoke the Text-to-columns command found on the Data tab:

excel-10

 

 

That will bring up a dialog box from which you can choose delimited or fixed width:

excel-11

 

 

 

 

 

 

 

 

 

 

 

In this case, it’s delimited (by a comma). So click the Next button to see step 2 of 3:

excel-12

 

 

 

 

 

 

 

 

 

 

You have to click the Comma checkbox, as it isn’t checked initially. Now click Finish. (You could click Next, but there’s nothing on step 3 that applies to this situation. Text-to-columns can be used in many other situations as well.

When you click Finish, you’ll see this:

excel-13

 

 

 

 

 

 

 

 

 

 

 

 

You have the names split, but you have last then first, not first then last. You can select B2:B24, click Cut (or Ctrl/x), then click on A2 (which contains “Jones”), then use Right-mouse click and select Insert Cut Cells:

excel-14

 

 

 

 

 

 

 
and then you’re done.

The third technique is only if you have Excel 2013 or later. It’s called Flash Fill. You start by typing the first result (Bob) in cell B2, and continue typing the 2nd result in C2. As you do, you’ll see Excel suggest the rest in a light gray color, because it recognizes the pattern:

excel-15

 

 

 

 

 

 

 

 

 

All you need do is press enter, and you’re done.

Then go to cell C2 and type the first 2 last names in C2 and D2:

excel-16

 

 

 

 

 

 
All there is to do is delete column A!

The only disadvantage to the latter 2 techniques is that they’re not dynamic. That is, if you change A2 to Williams, Jared, the data in cells B2 and C2 won’t change. But the formula-based version will change.

Learn more about IIL’s Microsoft Excel training >> 

Bob Umlas has been voted an “MVP” (Most Valuable Professional) by Microsoft each year since 1994 for his contributions to Excel online forums and he is known world-wide for his expertise. As an MVP, he meets yearly with fellow MVPs at Microsoft’s headquarters in Redmond, where he has access to the product developers. He has also been a beta tester for new versions of Excel since version 1.5 and is the author of several books including This isn’t Excel, it’s Magic! (available on the IIL Bookstore), Excel Outside the Box, and More Excel Outside the Box.

2 Comments

  • Monte Stimmel on December 15, 2015 12:52 am Reply

    Bob Umlas is a wealth of Excel Knowledge! These techniques are fantastic!

  • Joanne Chen on December 16, 2015 1:50 am Reply

    It’s helpful. Great to know the tips between new and old versions. Wait to learn more on 2013 Excel.

Leave a Comment

Your email address will not be published. Required fields are marked *

Phone: 800-325-1533 or +1-212-758-0177
Fax: +1-212-755-0777
110 East 59th Street
New York, NY 10022 USA