View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Stephen[_3_] Stephen[_3_] is offline
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