Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to separate First name and Last Name

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default How to separate First name and Last Name

Hi
one way:

sub foo()
Dim firstName as string
Dim lastName as string
Dim rng as range
set rng = activesheet.range("D3")
with rng
firstname=left(.value,instr(.value," ")-1)
lastname=mid(.value,instr(.value," ")+1,255)
end with
end sub

--
Regards
Frank Kabel
Frankfurt, Germany

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/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to separate First name and Last Name

I would also like to know, suppose Cell ntain telphone number, it can b
1 number only or 2 number, if there are 2 telephone number, it will b
separeted by a "/"

For example:

F5 = 11223344
or
F5 = 11111111 / 44444444

Then how can i know it has 1 or 2 phone number, and how can i separat
them if there are 2 number~

Thx

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default How to separate First name and Last Name

Hi
try

sub foo()
Dim tel_1 as string
Dim tel_2 as string
Dim rng as range
set rng = activesheet.range("D3")
with rng
if instr(.value,"/")0 then
tel_1=left(.value,instr(.value,"/")-2)
tel_2=mid(.value,instr(.value,"/")+2,255)
else
tel_1 = .value
end if
end with
end sub


--
Regards
Frank Kabel
Frankfurt, Germany

I would also like to know, suppose Cell ntain telphone number, it can
be 1 number only or 2 number, if there are 2 telephone number, it
will be separeted by a "/"

For example:

F5 = 11223344
or
F5 = 11111111 / 44444444

Then how can i know it has 1 or 2 phone number, and how can i

separate
them if there are 2 number~

Thx!


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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to separate First name and Last Name

I have solved all the problem !!!! Thx everyone hepling me!

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to separate First name and Last Name

Dim iloc as Long
if instr(activecell.Value,"\") then
iloc = Instr(activeCell.Value,"\")
firstnumber = Left(activecell.value,iloc-1)
secondnumber = Right(ActiveCell.Value, len(activecell.value)-iloc)
Else
firstnumber = ActiveCell.Value
secondnumber = ""
End if

--
Regards,
Tom Ogilvy

"michelle_ho " wrote in message
...
I would also like to know, suppose Cell ntain telphone number, it can be
1 number only or 2 number, if there are 2 telephone number, it will be
separeted by a "/"

For example:

F5 = 11223344
or
F5 = 11111111 / 44444444

Then how can i know it has 1 or 2 phone number, and how can i separate
them if there are 2 number~

Thx!


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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default How to separate First name and Last Name

Michelle

One way:

FirstName = Split([D3]," ")(0)
LastName = Split([D3]," ")(1)

To use this solution, you must have
Excel 2000 or later.

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"michelle_ho " skrev i en
meddelelse ...
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/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to separate First name and Last Name

Thx for all's replies!

It works!

I am using Frank Kabel 's suggestion. But I want to know, what if th
user didn't enter firstname, then how can I detect 1 words, or 2 word
entered by the user

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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default How to separate First name and Last Name

Hi
try
sub foo()
Dim firstName as string
Dim lastName as string
Dim ofind as integer
Dim rng as range
set rng = activesheet.range("D3")
with rng
ofind = instr(.value," ")
if ofind then
firstname=left(.value,ofind-1)
lastname=mid(.value,ofind+1,255)
else 'only one name entered
lastname = .value
end if
end with
end sub

--
Regards
Frank Kabel
Frankfurt, Germany

Thx for all's replies!

It works!

I am using Frank Kabel 's suggestion. But I want to know, what if the
user didn't enter firstname, then how can I detect 1 words, or 2

words
entered by the user?


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


  #10   Report Post  
Posted to microsoft.public.excel.programming
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/





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
separate two dates from a text string into two separate cells Tacrier Excel Discussion (Misc queries) 3 October 13th 08 08:53 PM
I wish to separate city, state, and zip into 3 separate columns Bob Woolbert Excel Worksheet Functions 1 July 11th 06 05:29 PM
Open Separate Excel Files in Separate Windows JTWood Excel Discussion (Misc queries) 3 May 7th 06 10:18 PM
Save 2 separate data imports in separate worksheets on the same ex Jay Excel Worksheet Functions 1 March 8th 06 01:31 PM
Open Excel files in separate sessions, not just separate windows? Bob at Dexia Design Excel Discussion (Misc queries) 1 October 18th 05 05:46 PM


All times are GMT +1. The time now is 02:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"