View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Ken Hudson Ken Hudson is offline
external usenet poster
 
Posts: 186
Default Separate a FirstLast text string into two columns

With your list in column A, this code should put the first name in column B
and the last in column C:

Make a back-up copy of your workbook.
Press Ctrl and F11 to open the Visual Basic Editor.
Select Insert and then Module.
Copy the code below and paste it into the module.
Close the Editor.
Go to Tools Macro Macros€¦
Highlight the macro and click Run.

---------------------------------


Sub SeparateNames()

Dim NumRows As Double
Dim Iloc As Integer
Dim Iloop As Double
Dim Iloop1 As Integer
NumRows = Range("A65536").End(xlUp).Row
For Iloop = 1 To NumRows
For Iloop1 = 2 To Len(Cells(Iloop, "A"))
If Mid(Cells(Iloop, "A"), Iloop1, 1) = _
UCase(Mid(Cells(Iloop, "A"), Iloop1, 1)) Then
Cells(Iloop, "B") = Left(Cells(Iloop, "A"), Iloop1 - 1)
Cells(Iloop, "C") = Right(Cells(Iloop, "A"), _
Len(Cells(Iloop, "A")) - Iloop1 + 1)
Exit For
End If
Next Iloop1
Next Iloop

End Sub

--
Ken Hudson


"drewannie" wrote:


Please advise on how to separate a text string that has no delimiters?
The cells contain names without spaces or commas in this format:
FirstnameLastname. The result I want is two columns with firstname in
one and lastname in the second column. The only thing distinguishing
the two desired fields within the string is an upper case letter at the
beginning of first and last names.

Thanks! :)


--
drewannie
------------------------------------------------------------------------
drewannie's Profile: http://www.excelforum.com/member.php...o&userid=36079
View this thread: http://www.excelforum.com/showthread...hreadid=558657