**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.

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**.

**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!

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

Discover MoreWhen 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 MoreYou can use the Alt+Enter keyboard shortcut while entering information in order to force your data onto multiple lines in a ...

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

2016-05-31 02:39:00

Arun Dutta

=TRIM(MID(SUBSTITUTE(" "&A2," ",REPT(" ",255)),{1,2,3,4,5}*255,255))

2016-04-21 19:34:19

Thomson

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

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

2015-04-02 05:09:12

DoubleJoy

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

2013-01-03 09:49:26

Michael Avidan - MVP

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

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

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

Michael Avidan

“Microsoft®” MVP – Excel

ISRAEL

2013-01-03 06:16:37

Michael Avidan - MVP

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

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

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

2012-12-22 10:38:00

Michael Avidan - MVP

=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

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

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.

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

Copyright © 2017 Sharon Parq Associates, Inc.

## Comments