View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JulieD JulieD is offline
external usenet poster
 
Posts: 12
Default How to separate First name and Last Name

Hi Michelle

if you just want to cycle through your records and split them into two
columns then this can be done using the Text to Columns feature on the Data
menu

if you're writing code and need to split the two up then one way is:

dim i as integer
dim firstName as string
dim lastName as string
dim fullName as string

fullName = Range("A1") 'or whatever to get the fullname
i = InStr(fullName, " ") 'returns the number of character that the space
relates to
firstName = left(fullName, i - 1) 'take the left portion of fullname
lastName = right(fullName, len(fullName) - i) 'take the right portion of
fullname

assumes - all names are in the first name / last name structure and that the
full names only have one space in them, hope this helps

Cheers
JulieD




"michelle_ho " wrote in message
...
Suppose in cell D3, the value is "Christine White".

I have two variables, firstName and lastName as String.

How can I separate "Christine White", so that firstName = "Christine"
and lastName = "White"??

Thx a lot!


---
Message posted from http://www.ExcelForum.com/