Hi There,
I have written a little script that should splitt FirstName, Mr.Ms.Miss and LastName. However, the raw data I received with which I will have to use my VB script, is a bit more complicated, and I can't solve that challenge yet. I need some tips from experts. :-)
[code=vb]
'Uses the Excel VBA split function
Sub MyExcelSplitCel ls()
Dim TempArray As Variant
Dim rwIndex, colIndex
With Sheet3
For rwIndex = 1 To .UsedRange.Rows .Count
TempArray = mySplit(Trim(.C ells(rwIndex, 1).Text))
For colIndex = 2 To UBound(TempArra y) + 2
.Cells(rwIndex, colIndex).Value = TempArray(colIn dex - 2)
Next
Next
End With
End Sub
Function mySplit(str As String) As Variant
ReDim myArray(0)
Dim counter As Integer
counter = 0
For x = 1 To Len(str)
Select Case Mid(str, x, 1)
Case ",", " " '".", "-"
If Len(myArray(cou nter)) > 0 Then
counter = counter + 1
ReDim Preserve myArray(counter )
End If
Case Else
myArray(counter ) = myArray(counter ) + Mid(str, x, 1)
End Select
Next
mySplit = myArray
End Function
[/code]
the Raw Data looks like: [code=Text]
AShok Kumar, Mr. Pandi
Aanei, Mr. Paul
Aarthi, Mrs. Aravamudhan
Abbott, Mr. Neil
Abcouwer, Mr. Eric
Abd Manaf, Mrs. Fazilah
Abdul Aziz, Mr. Ahmed
Abdulgapul, Mr. Al-Ameen B
Abdullaeva, Miss Roziya
Abhishek, Mr. Banchhor
Abhishek, Mr. Roy
Abisamra, Mr. Atef
Able, Mr. Klaus
Abraham, Mr. Lionel
Achuth Rao, Mr. Subramania Rao
Acosta, Mr. Ernesto F.
Adefioye, Mr. William
Adeline Jenitha, Ms. Wilfred
Adeyemi, Mr. Peter Adekunle (Peter)
Adkinson, Mr. Desmond John
Ageev, Mr. Fedor Borisovitch (Fedor)
[/code]
Basically, I need the FirstName (with Middle Name) in one column, Title in another, and LastName also.
The Script I wrote works, as long as there aren't MiddleNames. Does anybody have a hint? I would highly appreciate it.
Regards,
I have written a little script that should splitt FirstName, Mr.Ms.Miss and LastName. However, the raw data I received with which I will have to use my VB script, is a bit more complicated, and I can't solve that challenge yet. I need some tips from experts. :-)
[code=vb]
'Uses the Excel VBA split function
Sub MyExcelSplitCel ls()
Dim TempArray As Variant
Dim rwIndex, colIndex
With Sheet3
For rwIndex = 1 To .UsedRange.Rows .Count
TempArray = mySplit(Trim(.C ells(rwIndex, 1).Text))
For colIndex = 2 To UBound(TempArra y) + 2
.Cells(rwIndex, colIndex).Value = TempArray(colIn dex - 2)
Next
Next
End With
End Sub
Function mySplit(str As String) As Variant
ReDim myArray(0)
Dim counter As Integer
counter = 0
For x = 1 To Len(str)
Select Case Mid(str, x, 1)
Case ",", " " '".", "-"
If Len(myArray(cou nter)) > 0 Then
counter = counter + 1
ReDim Preserve myArray(counter )
End If
Case Else
myArray(counter ) = myArray(counter ) + Mid(str, x, 1)
End Select
Next
mySplit = myArray
End Function
[/code]
the Raw Data looks like: [code=Text]
AShok Kumar, Mr. Pandi
Aanei, Mr. Paul
Aarthi, Mrs. Aravamudhan
Abbott, Mr. Neil
Abcouwer, Mr. Eric
Abd Manaf, Mrs. Fazilah
Abdul Aziz, Mr. Ahmed
Abdulgapul, Mr. Al-Ameen B
Abdullaeva, Miss Roziya
Abhishek, Mr. Banchhor
Abhishek, Mr. Roy
Abisamra, Mr. Atef
Able, Mr. Klaus
Abraham, Mr. Lionel
Achuth Rao, Mr. Subramania Rao
Acosta, Mr. Ernesto F.
Adefioye, Mr. William
Adeline Jenitha, Ms. Wilfred
Adeyemi, Mr. Peter Adekunle (Peter)
Adkinson, Mr. Desmond John
Ageev, Mr. Fedor Borisovitch (Fedor)
[/code]
Basically, I need the FirstName (with Middle Name) in one column, Title in another, and LastName also.
The Script I wrote works, as long as there aren't MiddleNames. Does anybody have a hint? I would highly appreciate it.
Regards,
Comment