Cell Contents as Variable in VBA

  • Thread starter Thread starter Gandalf252002
  • Start date Start date
G

Gandalf252002

Hi all,

I am relatively new to macros and VBA scripting. Is there a way I can
use the date in a particular cell as a variable in VBA code? I have
some reports based on filters. So I would like to be able to specify
a date in one cell. Then in the code when I run filters it would be
based on the date in that cell.

Any help would be greatly appreciated.
 
Hi,

X=[A1]

stores the value of cell A1 on the active sheet in the variable A1.

Y = Sheets("Budget").[A1]

stores the value of A1 on the Budget sheet in the variable Y

It is also good practice to declare your variables:
Dim X
or
Dim X as Integer
what you dim the variable as depends on the type of data to be stored in the
variable, by not stating the data type (first example), Excel decides based
on the value you put into it.
 
Back
Top