View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
MrScience MrScience is offline
external usenet poster
 
Posts: 21
Default parsing full names in to 3 columns

Okay, sorry for all the confusion. Here's the procedure we talked
about yesterday revised so that it will work whether or not there are
any blank rows. I've tested it using the data you originally supplied
and it works fine without errors. Just remember to set your range
reference to whatever you have. I've commented the line in the code
where you need to do this.

Sub FirstToLast()

Dim lkforComma As Integer
Dim lkforSpace As Integer
Dim fName, mName, lName As String
Dim myRange As Range
Dim myCell As Range

Set myRange = Range("A1:A9") 'set the range for whateve you
need

For Each myCell In myRange
If myCell < "" Then 'blank cells will be ignored

Set nextCell = myCell.Offset(1, 0)
Set firstName = myCell.Offset(0, 1)
Set middleName = myCell.Offset(0, 2)
Set lastName = myCell.Offset(0, 3)

lkforComma = InStr(myCell, ",")
lName = Left(myCell, lkforComma - 1)
fName = Mid(myCell, lkforComma + 2)
lkforSpace = InStr(fName, Chr(32))
mName = Mid(fName, lkforSpace + 1)
fName = Mid(fName, 1, lkforSpace - 1)
firstName.Value = fName
middleName.Value = mName
lastName.Value = lName

End If
Set myCell = nextCell
Next myCell

MsgBox "File Done"

End Sub