Excel: Split names into columns Macro?

We have a document filled with tons of data. There is one column that states people's names. Some with middle names, some with not. But the problem is it's all in one column.

What we need is a macro that can separate all of these into 3 separate columns.

I have a example of what I'm trying to say attached to this.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
This is one way it could be done in VB.

Dim sFirst As String
Dim sMI As String
Dim sLast As String
Dim intPos As Integer
Dim strParts() As String

'remove comma space pair with comma
strName = Replace(strName, ", ", ",")
intPos = InStr(strName, ",")
sLast = Left(strName, intPos - 1)

If InStr(Mid(strName, intPos + 1), " ") Then
    strParts = Split(Mid(strName, intPos + 1), " ")
    sFirst = strParts(0)
    sMI = Left(strParts(1), 1)
    sFirst = Mid(strName, intPos + 1)
    sMI = ""
End If
Pancake_EffectAuthor Commented:
(Sorry I'm only familiar with macros) with that VB is there a way to specify columns such as A:A go to A:C? Because when we get this data it's filled with like 50 columns of other data that's not names, but other data.
Martin LissOlder than dirtCommented:
And I'm obviously not an Excel programmer but this works for one row. It assumes the data is in A1 and that B1, C1 and D1 are the output cells.

Sub Macro1()
    Dim strParts() As String

    strParts = Split(Range("A1").Value)
    ActiveCell.FormulaR1C1 = strParts(0)
    If UBound(strParts) = 2 Then
    ' there's a middle name
        ActiveCell.FormulaR1C1 = Left(strParts(1), 1)
        ActiveCell.FormulaR1C1 = strParts(2)
        ActiveCell.FormulaR1C1 = strParts(1)
    End If
End Sub
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

The assumption for the following "name" formulas is there may/may not be a middle name.  Each name that is found, including punctuation is separated by the other names by one space and there are no other spaces, otherwise.

This formula finds the n-th occurrance of a character in a string.  We can separate the names by looking for the first space to get the first name, then second space (if it exists) to separate the middle from the last name.

For example, a non-case sensitive (using Search instead of Find) search for the first space in "John C. Wayne", you'd use something like:

=SEARCH("^^",SUBSTITUTE("John C. Wayne"," ","^^",1))

So the space is replaced with the characters "^^", then a search is performed on "^^" to find the position of the first instance of the space.

The second instance of space, if it exists would be using the formula:

=SEARCH("^^",SUBSTITUTE("John C. Wayne"," ","^^",2))

So, for your example, in cell C23, D23 and E23, we'd use variations of this formula to get the first, middle (if it exists), and last name, respectively.  And, we use the IFERROR to advise us whether there is or isn't a middle name (re: second space):

[C23]=LEFT(A23,SEARCH("^^",SUBSTITUTE(A23," ","^^",1))-1)
[D23]=IFERROR(MID(A23,SEARCH("^^",SUBSTITUTE(A23," ","^^",1))+1,SEARCH("^^",SUBSTITUTE(A23," ","^^",2))-SEARCH("^^",SUBSTITUTE(A23," ","^^",1))-1),"")
[E23]=IFERROR(RIGHT(A23,LEN(A23)-SEARCH("^^",SUBSTITUTE(A23," ","^^",2))),RIGHT(A23,LEN(A23)-LEN(C23)-1))

And you can copy down these formulas, as much as needed.

See attached.

Good Luck!

There OUGHT to be a SPLIT function at the formula level, lol, but this approach is the closest I've found.

Pancake_EffectAuthor Commented:
dlmille that looks very good!

One question, what values do I change if I want to change column or rows?

I tried changing some values and it just messes it up
Well, the formulas all look at column A for starters, And formula in E column cheats and uses the length found in column C.  The formulas on row 23, work with A23.

You can drag A23 to another location, and it would change the references on C,D, E23.

But, assuming your data starts at A2, and you wanted results on B,C, and D2

[C2]=LEFT(A2,SEARCH("^^",SUBSTITUTE(A2," ","^^",1))-1)
[D2]=IFERROR(MID(A2,SEARCH("^^",SUBSTITUTE(A2," ","^^",1))+1,SEARCH("^^",SUBSTITUTE(A2," ","^^",2))-SEARCH("^^",SUBSTITUTE(A2," ","^^",1))-1),"")
[E2]=IFERROR(RIGHT(A2,LEN(A2)-SEARCH("^^",SUBSTITUTE(A2," ","^^",2))),RIGHT(A2,LEN(A2)-LEN(C2)-1))

Does that help?

If not, tell me what cell range have the name and where you want to put the first, mid, last and I'll provide that transformation.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pancake_EffectAuthor Commented:
I'm sorry guys, but I've thought about this for a couple days, and feel that too much effort was spent by each of us with excellent solutions to warrant a B grade, and therefore I'm objecting.

@Pancake_Effort - please read the following guidelines for grading:

Grading Guidelines

A: The Expert(s) either provided you with a thorough and informative answer or with a link to information that answered your question.

B: The Expert(s) provided an acceptable solution, or a link to an acceptable solution but you needed more information to complete the task.

C: You have given the Expert(s) ample time to respond to your clarification posts and you have responded to each of their posts providing requested information, and the answer, after clarification, lacks finality or does not address the issue presented

Based on my re-read, it does not appear from my perspective that you needed more information to complete the task - in fact, it appears your understood the proposed solutions perfectly and were very happy with the result.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.