Breakup text string that is separated by commas

Looking the syntax to break up a text string into 3 fields (last, First, MI)

Smith, John, L

Not sure what to use.

Karen
Karen SchaeferBI ANALYSTAsked:
Who is Participating?
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.

Ken ButtersCommented:
http://www.example-code.com/vb/splitComma.asp

Dim s As String
s = "Chilkat Mail, ActiveX Component, $99, free upgrades, 1-Year Support"

Dim fields() As String

' Split the string at the comma characters and add each field to a ListBox
fields() = Split(s, ",")

For i = 0 To UBound(fields)
    List1.AddItem Trim$(fields(i))
Next

0
TracyVBA DeveloperCommented:
You would use the split function.  See the attached example.  

Open the file go to Tools --> Macros --> Macro, select SplitNames and click Run.
Sub SplitNames()

    Dim myarray As Variant
    Dim i As Long
    Dim lastRow As Long
    Dim k As Integer
    
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 2 To lastRow
        myarray = Split(Cells(i, 1).Value, ",")
        k = 2
        For p = LBound(myarray) To UBound(myarray)
            Cells(i, k).Value = myarray(p)
            k = k + 1
        Next p
    Next i

End Sub

Open in new window

Book1.xls
0
TracyVBA DeveloperCommented:
To remove any extra spaces add the trim function (this has been added in the attached).

Cells(i, k).Value = Trim(myarray(p))


Book2.xls
0

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.