Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Defining a variable length area for output. | Excel Discussion (Misc queries) | |||
defining a variable-size worksheet area for charting | Excel Worksheet Functions | |||
defining a variable-size worksheet area for copying & pasting | Excel Worksheet Functions | |||
Defining UserForm Caption from a Variable | Excel Worksheet Functions | |||
Defining "Month" as a variable in VBA | Excel Discussion (Misc queries) |