Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Separating Names into Individual Columns.

Separating Names into Individual Columns

by Allen Wyatt
(last updated April 21, 2016)

15

Lance has a set of names in a workbook. The names are all in column A, and some have first and last name, while others use first, middle, and last names. He needs to separate the names into individual columns, but the Text to Columns wizard doesn't provide satisfactory results. It does the separation OK, but the two-vs.-three names issue means that Lance need to do a lot of manual massaging of the data once it is split up.

The solution to the problem is to not rely on the Text to Columns wizard, but instead use a number of formulas to get the names into columns. The results you achieve still depend, in large part, on the condition of the data you are parsing. If your data is in the format "first middle last" (with the middle name being optional), then you can use the following formula to pull out the first name:

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

This formula checks for the first space in the name, and then assumes that everything before that space is the first name. The next formula is used to determine if there is a middle name, and if there is, display it:

=IF(ISERROR(SEARCH(" ", RIGHT(A1, LEN(A1) - _
SEARCH(" ", A1, 1)), 1)) = TRUE, "", _
LEFT(RIGHT(A1,LEN(A1) - SEARCH(" ", A1, 1)), _
SEARCH(" ", RIGHT(A1, LEN(A1) - SEARCH(" ", _
A1, 1)), 1) - 1))

The formula checks for the existence of a second space in the name. If an error is generated (there is no second space) then the formula returns nothing; there is no middle name. If a second space is detected (there is no error generated), then the formula returns everything from after the first space up through the second space.

=RIGHT(A1,LEN(A1)-LEN(B1)-LEN(C1)-IF(C1="",1,2))

This formula relies on the results that were returned for both the first and middle names. It returns everything left in the original name after accounting for the length of the first name (assumed in cell B1) and the middle name (assumed in C1).

Again, these formulas work if the original data is in the "first last" or "first middle last" format. If there are qualifiers in the name such as Ms., Dr., Jr., or III, then you won't get satisfactory results. In addition, if the last name contains a space (as in "John van Kamp" or "Mary Anne St. Marie"), then you also won't get satisfactory results.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12383) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Separating Names into Individual Columns.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Spacing After Sentences

Word can check to see if you have a consistent number of spaces at the end of your sentences.

Discover More

Using the TRUNC Worksheet Function

Want to chop off everything after a certain point in a number? The TRUNC function can help with this need.

Discover More

Stopping Validated Data from being Overwritten

Data Validation is a great tool to make sure that data entered in a cell meets whatever criteria you decide. Its weakness, ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Stopping a Formula from Updating References

Insert or delete a column, and Excel automatically updates references within formulas that are affected by the change. If you ...

Discover More

Counting Jobs Completed On a Date

When you store the date and time in a single cell, it can be a bit confusing to count how many cells contain a particular ...

Discover More

Simulating Alt+Enter in a Formula

You can use the Alt+Enter keyboard shortcut while entering information in order to force your data onto multiple lines in a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 3?

2016-05-31 02:39:00

Arun Dutta

Why we use 255 on mention below formula please confirm ??
=TRIM(MID(SUBSTITUTE(" "&A2," ",REPT(" ",255)),{1,2,3,4,5}*255,255))


2016-04-21 19:34:19

Thomson

Another way is to use PowerQuery.
Just create a table with all name into a list named "NameList".

let
Source = Excel.CurrentWorkbook(){[Name="NameList"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Full Name", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type","Full Name",Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true),{"First Name", "Surname"})
in
#"Split Column by Delimiter"


2016-04-21 12:07:59

John

Assume the full name is in cell A2 and that all names contain one or two spaces, enter the following formulas in cells B2 and C2 --

B2: =REPLACE(A2,FIND(" ",A2),1,";")

C2: =IFERROR(REPLACE(B2,FIND(" ",B2),1,";"),REPLACE(B2,FIND(";",B2),1,";;")

B2 will replace the first space with a semicolon.

C2 will replace the second space with a semicolon unless there is no second space, in which case it will replace the first semicolon with two semicolons.

Or, alternatively, under the same assumptions --

B2: =SUBSTITUTE(A2," ",";")

C2: =IF(ISERROR(FIND(";",B2,FIND(";",B2)+1)),SUBSTITUTE(B2,";",";;"),B2)

B2 will replace all spaces with semicolons.

C2 will look for a second semicolon. If it can't find one, it will replace the first semicolon with a double semicolon.

Follow either approach with a text-to-columns command using the semicolon as a delimiter.


2016-04-21 08:23:07

Rick

DoubleJoy it seems the best solution for the desired results would be to do a text to columns function (on the data tab) and use a space as the delimiter.


2015-04-02 05:09:12

DoubleJoy

Dear Sir,

Kindly assist me. I want to split this text into 4 separate cells. How can I achieve this. [160004/02/103 DEPOT FLOAT/WAREHOUSING/ ABEOKUTA DEPOT]


2013-10-20 16:05:25

GARY HARLOW

I found this Tip to do just as it was described. Where the name was "Eva Marie St. James", I eliminated the space between St. and James in the original cell to sort it in a recognizable location for future look up in the last name column (St.James). Company names needed to be rearranged to place the look up name in the last name column, but Excel will handle that with the "Insert Copied Cell" function.


2013-01-03 09:49:26

Michael Avidan - MVP

Don,

As for the use of 'Column number' - I never expect that the user will iuse my suggested formulas without understanding each and every part of them.

I addition, if you really want to take care of typing errors (not TIPOS) - the present pictures shows such errors and suggested formulas.
(As far as I could see, your formulas do not take care of such cases).

http://ipic.se/img/1357224416.png

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL


2013-01-03 08:42:04

Don Bruck

A couple of more things...
The "Column()-2" only seems to work when columns A through D are used. When I shifted everything right the results were incorrect.
I looked at all of the recommendations, identify which (a) took care of errors in inputs (i.e. leading, trailing and multiple inter-name spaces); the number of functions used and the number of parameters(a measure of how mega is the formula). Here is what I came to, using parts of each solutions:
* FirstName =LEFT(TRIM(A51),FIND(" ",TRIM(A51))-1)
* MiddleNameInitial = IF(ISERR(FIND(" ",RIGHT(TRIM(A51),LEN(TRIM(A51))-LEN(B51)-1))),"",TRIM(MID(SUBSTITUTE(TRIM($A51)," ",REPT(" ",255)),255,255)))
* LastName = TRIM(RIGHT(TRIM(A51),LEN(TRIM(A51))-(LEN(B51)+LEN(C51)+IF(LEN(C51)>1,2,1))))


2013-01-03 06:23:32

Michael Avidan - MVP

... and if, you all, had in mind what is shown in the present picture - then I would expect a comma to be typed between the names - AND a double comma where there is no Middle name.

http://ipic.se/img/1357212080.png

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL


2013-01-03 06:16:37

Michael Avidan - MVP

Allan,

Check the picture in the link.

The formulas in column C+D are identical.

http://ipic.se/img/1357211564.png

Does it, now, clear everything ?

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL


2013-01-02 15:39:15

Don Bruck

Similar to Alan's experience, when I tried the recommended solution the second column has the middle name/initial if it exist, otherwise it has the last name. To fix this there needs to be a test in the Middle Name/Initial column for another space after what is found and a test in the Last Name column to see if the length of the Middle Name/Initial is greater than 0.

Further, I have zero confidence that people will enter the data correctly. They will copy and paste, which results in in trailing and leading spaces, as well as stutter on the space bar without noticing.

The solution from there is to (a)add a column using the Trim() function then work from there, or (b) copy the Trim()ed names and PasteValues back to where you started, or (c) run a macro to trim the excess spaces from the names or (d) use the following "mega formulas", as hated as they are, for data in row 2 where Column A = Full Name, Column B = First Name, Column C = Middle Name/Initial, Column D = Last Name.
First Name: =TRIM(LEFT(TRIM(A2),FIND(" ",TRIM(A2))))
Middle Name/Initial: =IF(ISERR(FIND(" ",RIGHT(TRIM(A2),LEN(TRIM(A2))-LEN(B2)-1))),"",TRIM(LEFT(TRIM(RIGHT(TRIM(A2),LEN(TRIM(A31))-LEN(B2)-1)),FIND(" ",TRIM(RIGHT(TRIM(A2),LEN(TRIM(A2))-LEN(B2)-1))))))
Last Name: =TRIM(RIGHT(TRIM(A2),LEN(TRIM(A2))-(LEN(B2)+1+LEN(C2)+IF(LEN(C2)>1,1,0))))

Please Note
* The first formula is the same as the recommended solution, except for the Trim()ing of the name field.
* The Middle Name Initial formula checks for a separating space to the right of the First Name plus a space, leaving this blank if not found. The Else (false) portion is not unlike the First Name formula, except it strips off the First Name and following space from the Trim()ed name.
* The last name adds the Len() of the First Name, plus 1 for the space after it, plus the Len of the Middle Name/Initial, plus 1 for a space if there is a Middle Name/Initial (LEN>0).


2012-12-23 04:52:42

Alan

Sorry - I must be a bit (lot) dense.
I can't get the middle name formula to work. I realise that it is split over four paragraphs. I have tried just deleting the paragraphs to but it all on a single line - no dice. I have tried to remove any spaces in the formula - no dice.

The formula by Michael Avidan is great if all the names consist of two parts ... but if it is a mixture of two and three names, I get the middle and surnames appearing in the same column.
?????? What am I doing wrong?


2012-12-22 10:44:55

Juan

Could you explain, Michael, your formula to extract middle name, please? I don't understand why you use trim, substitute and column function. Thank you very much


2012-12-22 10:38:00

Michael Avidan - MVP

...and if one can assume that the Name string will not exceed 255 characters - then the formula will look like this:

=TRIM(MID(SUBSTITUTE($A6," ",REPT(" ",255)),255*(COLUMN()-2),255))

and copied across.

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL


2012-12-22 07:13:36

Michael Avidan - MVP

There is no need for such a "MEGA" formula.

It can be shorten by, at least, 50% as shown here:

http://ipic.se/img/1356177941.png

In addition - a very simple Split Text UDF can be used as proposed by John Walkenbach:

http://spreadsheetpage.com/index.php/tip/the_versatile_split_function/

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL



This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.