PDA

View Full Version : Solved: Variable address backwards reading



snoopfan
05-10-2011, 02:55 AM
Dear all,

I am concerned how to read the address of the variable that has been assigned a cell, moreover let me show you by example...



Public dh_PS1 As Double

dh_PS1 = Worksheets(1).Range("PrCond_In").Cells(3, 4)



so after using the variable later on, I would like to automatically have access to the cell via dh_PS1, I tried dh_PS1.Address(); but that did not seem to function

Anyone could help?

GTO
05-10-2011, 03:10 AM
Hi snoopfan,

dh_PS1 is returning a Property of the cell, in this case, the .Value property. If you want to retain a reference to the cell itself (so that you can later get properties of the cell, such as .Address), you just need to set a reference to the Range (in this case, the single cell).
Public MyCell as Range

Set MyCell = ThisWorkbook.Worksheets(1).Range("PrCond_In").Cells(3, 4)
Does that help?

Mark

snoopfan
05-10-2011, 03:16 AM
Hi Mark,

Thanks for the reply.

So in other words, there is no way for me to access the Cell from the variable which has been declared as Double? Since I have a lot of other variables, and creating a range for every one of them will be a pain. I was just looking for a way to access a cell from a variable which is used in the program.

GTO
05-10-2011, 03:28 AM
I am afraid not. Since the variable just contains a numeric value, it really has no relationship to the cell or anything else. Does that make sense?

snoopfan
05-10-2011, 04:46 AM
I suppose...

Thank you!