Forum Discussion
Separate full name field into three separate columns.
- Nov 17, 2019
mnelsonhd Hi. Looks like you have some which contain a middle initial and some which don't. The way I'd handle this is to process the name separating the parts by using the spaces as a separator. Where the name is in three parts (containing a middle initial), process one way, and for those without, process a different way. If all of the names are in the first column of the sheet and there are no empty rows in the middle, something like:
Function SplitName()
Dim names() As String
For i = 1 To Rows.Count
If Cells(i, 1).Value = "" Then
' No more data to process
Exit Function
Else
' Process the cell
names = Split(Cells(i, 1).Value)
' If it's two names, put into first and last name
If UBound(names()) = 1 Then
Cells(i, 3).Value = names(0)
Cells(i, 5).Value = names(1)
Else
' Otherwise, put the middle initial or name into the middle cell
Cells(i, 3).Value = names(0)
Cells(i, 4).Value = names(1)
Cells(i, 5).Value = names(2)
End If
End If
Next i
End Function