ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA routine to assign first name only to a variable (https://www.excelbanter.com/excel-programming/305813-vba-routine-assign-first-name-only-variable.html)

fitful_thought

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



Frank Kabel

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


.


Frank Kabel

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


.


JulieD

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





fitful_thought

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







Tom Ogilvy

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





fitful_thought

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








All times are GMT +1. The time now is 01:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com