VBA routine to assign first name only to a variable

  • Thread starter Thread starter fitful_thought
  • Start date Start date
F

fitful_thought

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.
 
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 pos>0 then
fname=left(fullname,pos-1)
else
fname=""
end if
msgbox fname
 
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 pos>0 then
fname=left(fullname,pos-1)
else
fname=""
end if
msgbox fname
 
Hi David

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

Cheers
JulieD
 
Thanks Tom,

I have 2002.
Your method is very concise.
Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top