Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA routine to assign first name only to a variable

Hi,

Cells(1, 1) contains the value
Annette Thompson

How do I get the variable fName to = Annette?

Any help at all will be much appreciated.


--
Regards,
David


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default VBA routine to assign first name only to a variable

Hi
one way:

dim rng as range
dim fname
dim fullname
dim pos as integer

set rng = activesheet.cells(1,1)
fullname=rng.value
pos = instr(fullname, " ")
if pos0 then
fname=left(fullname,pos-1)
else
fname=""
end if
msgbox fname


-----Original Message-----
Hi,

Cells(1, 1) contains the value
Annette Thompson

How do I get the variable fName to = Annette?

Any help at all will be much appreciated.


--
Regards,
David


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default VBA routine to assign first name only to a variable

Hi
one way:

dim rng as range
dim fname
dim fullname
dim pos as integer

set rng = activesheet.cells(1,1)
fullname=rng.value
pos = instr(fullname, " ")
if pos0 then
fname=left(fullname,pos-1)
else
fname=""
end if
msgbox fname


-----Original Message-----
Hi,

Cells(1, 1) contains the value
Annette Thompson

How do I get the variable fName to = Annette?

Any help at all will be much appreciated.


--
Regards,
David


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default VBA routine to assign first name only to a variable

Hi David

fname = left(cells(1,1),instr(cells(1,1)," ")-1)

Cheers
JulieD


"fitful_thought" wrote in message
...
Hi,

Cells(1, 1) contains the value
Annette Thompson

How do I get the variable fName to = Annette?

Any help at all will be much appreciated.


--
Regards,
David




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA routine to assign first name only to a variable

Thanks JulieD,
Works like a charm.

--
Regards,
David

"JulieD" wrote in message
...
Hi David

fname = left(cells(1,1),instr(cells(1,1)," ")-1)

Cheers
JulieD


"fitful_thought" wrote in message
...
Hi,

Cells(1, 1) contains the value
Annette Thompson

How do I get the variable fName to = Annette?

Any help at all will be much appreciated.


--
Regards,
David








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA routine to assign first name only to a variable

if you have xl2000 or later

fname = Split(Cells(1,1)," ")(0)

--
Regards,
Tom Ogilvy


"fitful_thought" wrote in message
...
Hi,

Cells(1, 1) contains the value
Annette Thompson

How do I get the variable fName to = Annette?

Any help at all will be much appreciated.


--
Regards,
David




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA routine to assign first name only to a variable

Thanks Tom,

I have 2002.
Your method is very concise.
Thank you.
--
Regards,
David
"Tom Ogilvy" wrote in message
...
if you have xl2000 or later

fname = Split(Cells(1,1)," ")(0)

--
Regards,
Tom Ogilvy


"fitful_thought" wrote in message
...
Hi,

Cells(1, 1) contains the value
Annette Thompson

How do I get the variable fName to = Annette?

Any help at all will be much appreciated.


--
Regards,
David






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
Assign value to a variable name Gnarlodious Excel Discussion (Misc queries) 2 August 20th 06 07:10 AM
How to keep a Variable alive after a Call to Sub Routine Dennis Excel Discussion (Misc queries) 2 July 27th 05 10:57 PM
Assign value to variable rroach Excel Discussion (Misc queries) 1 July 13th 05 05:24 AM
Variable VB to assign new sheet name Kevin M Excel Worksheet Functions 0 June 17th 05 12:15 AM
Assign Formula to Variable James Stephens Excel Programming 3 February 26th 04 04:16 PM


All times are GMT +1. The time now is 01:49 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"