Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default selection.cells(1).value

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?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default selection.cells(1).value

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


"greg" wrote:

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?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default selection.cells(1).value

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.
--
HTH...

Jim Thomlinson


"greg" wrote:

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?




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Selection - Paste Selection - Delete Selection Uninvisible Excel Programming 2 October 25th 07 01:31 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
Get a range of cells from a selection of cells danhattan Excel Programming 4 March 29th 07 11:22 PM
Macro to select cells and then new selection from selected cells Rewop Eilsel Excel Programming 0 June 6th 06 04:25 PM
Skip cells with TAB/SHIFT+TAB but allow arrow keys/mouse selection of skipped cells Wescotte Excel Programming 1 June 6th 05 07:00 PM


All times are GMT +1. The time now is 08:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"