How can i write a macro to seperate "lastname, firstname" into two

M

Mark

I have a list of names in an Excel worksheet. Unfortunately, the data is
concatenated "lastname, firstname" and is of variable length. Please provide
the VB Macro code I can use to seperate the data into two columns.
 
G

Gary''s Student

Sub splitum()
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
s = Split(Cells(i, "A").Value, ", ")
Cells(i, "B").Value = s(0)
Cells(i, "C").Value = s(1)
Next
End Sub

This assumes that the original list is in column A and the parts go in cols
B & C.

Adapt the code to your needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top