Left three text characters

M

Mike

I have a variable called "myMonth". I would like this
variable to be set to the first three text characters in
cell "G3".

For instance, if G3 is January, I'd like for myMonth to
equal "Jan"

I know that in Excel, I would have the formula be =left
(D3,3). How do I put this into VB code?

Thanks,
Mike.
 
J

Jake Marx

Hi Mike,

It's very similar to the worksheet function:

myMonth = Left$(Sheets("Sheet1").Range("G3").Value, 3)

You may want to use .Text instead of .Value, depending on what is actually
stored in the cell - the Text property returns the text displayed to the
user, while the Value property returns the actual value of the cell.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
M

Mike

Thanks, Jake!

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

It's very similar to the worksheet function:

myMonth = Left$(Sheets("Sheet1").Range("G3").Value, 3)

You may want to use .Text instead of .Value, depending on what is actually
stored in the cell - the Text property returns the text displayed to the
user, while the Value property returns the actual value of the cell.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

I have a variable called "myMonth". I would like this
variable to be set to the first three text characters in
cell "G3".

For instance, if G3 is January, I'd like for myMonth to
equal "Jan"

I know that in Excel, I would have the formula be =left
(D3,3). How do I put this into VB code?

Thanks,
Mike.

.
 
J

Jake Marx

You're welcome, Mike - glad to help!

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Thanks, Jake!

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

It's very similar to the worksheet function:

myMonth = Left$(Sheets("Sheet1").Range("G3").Value, 3)

You may want to use .Text instead of .Value, depending on what is
actually stored in the cell - the Text property returns the text
displayed to the user, while the Value property returns the actual
value of the cell.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

I have a variable called "myMonth". I would like this
variable to be set to the first three text characters in
cell "G3".

For instance, if G3 is January, I'd like for myMonth to
equal "Jan"

I know that in Excel, I would have the formula be =left
(D3,3). How do I put this into VB code?

Thanks,
Mike.

.
 
T

Tom Ogilvy

Since Cells(3,4) refers to D3 rather than G3 as requested, and otherwise,
your post pretty much duplicates what Mr. Marx said, what was the added
value of your post? I don't want to miss the important message you intended
to convey.
 
Top