Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Defining a Variable

Hi -

I'm trying to define a variable based on the contents in a cell. I
used the variable in different times in the macro to define the month
of the year. Here is what I came up with so far.

The data I receive has the date in the following format in cell A1.
8/20/2003 12:23 PM

In my macro, I have a variable defined as follows.
month = left(A1,1)
Result - The month variable in the example above would be 8. This is
what I am looking for.

The problem I have now is that when October comes around, the month
variable will only pull the one number (1 for 10). If I change the
month variable to (month = left(A1,2)), I would get 8/ as my variable
in the example above.

Is there a way to add an if statement in defining a variable.

Thanks.
Stephen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Defining a Variable

Of course, in VBA it would be

myMonth=MONTH(Range("A1").Value)

--

HTH

Bob Phillips

"Bob Phillips" wrote in message
...
Stephen,

Why not use
month = MONTH(A1)

probably best to rename the variable le as well, not use a VBA keyword.

--

HTH

Bob Phillips

"Stephen" wrote in message
m...
Hi -

I'm trying to define a variable based on the contents in a cell. I
used the variable in different times in the macro to define the month
of the year. Here is what I came up with so far.

The data I receive has the date in the following format in cell A1.
8/20/2003 12:23 PM

In my macro, I have a variable defined as follows.
month = left(A1,1)
Result - The month variable in the example above would be 8. This is
what I am looking for.

The problem I have now is that when October comes around, the month
variable will only pull the one number (1 for 10). If I change the
month variable to (month = left(A1,2)), I would get 8/ as my variable
in the example above.

Is there a way to add an if statement in defining a variable.

Thanks.
Stephen





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
Defining a variable length area for output. JHB Excel Discussion (Misc queries) 2 August 5th 09 10:43 PM
defining a variable-size worksheet area for charting z.entropic Excel Worksheet Functions 0 August 15th 07 06:18 PM
defining a variable-size worksheet area for copying & pasting z.entropic Excel Worksheet Functions 3 August 11th 07 09:30 PM
Defining UserForm Caption from a Variable [email protected] Excel Worksheet Functions 1 January 3rd 07 02:30 PM
Defining "Month" as a variable in VBA Colin Vicary Excel Discussion (Misc queries) 2 February 22nd 06 05:58 PM


All times are GMT +1. The time now is 02:13 AM.

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

About Us

"It's about Microsoft Excel"