selection.cells(1).value

G

greg

Hello,
I am working with the selection object.

If I select a single cell. my selection.Cells.Count = 1.

I can do this and get the correct value of the cell:
selection.cells(1).value

However I can also do this:
selection.cells(0).value
and get the value of the cell above the selected.
Is this correct? Why is this happening?
Seems a little scary?
 
J

Joel

Line 1 and 2 are equivalent

selection.cells(1).value

cells(rowoffset:=1,columnoffset:=0)


so what you are saying is Range("A1").cells.count = Range("A2").cells.count
= 1
 
J

Jim Thomlinson

Although it is interesting that you can read beyond the boundaries of the
range object it is not exactly a fatal flaw. The reason that this is
happening is that a range object is essentially just a pointer to the first
cell with a reference to the number of cells that encompass the range. If you
offset from the pointer outside of the valid range of the object then you get
into cells that are not part of the range object. Very similar to C/C++
programming where you can read or write beyond the boundaries of an array or
such.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top