Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Strange Range.item behavior?

Can someone explain this to me?

From the immediate window:
?Range("A1").Item(3,1).address
$A$3
?Range("A1").Item(3).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3,1).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3).address
$C$1 <----!!!???

The last one there is where my confusion lies.

I'm sorting a range with the code below(rough example):
---------------------------------------------------------------------------------------------
Set rDataRng = Range(Range("A1"), Range("G10"))
With rDataRng
.Value = .Value
.Sort Key1:=.Item(2, 1), Order1:=xlDescending, OrderCustom:=1, _
Orientation:=xlLeftToRight
End With
---------------------------------------------------------------------------------------------

I initially had .Item(2) in there as the Key1 entry, which caused me to
stumble upon this (what I see as) strange behavior.
Is this a bug or one of those "by design" features?

Thanks for any input.
-Jeremy


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Strange Range.item behavior?

You are only referencing one dimension of a two dimension array. Arguments
are read right to left (backwards from what you would think) so you are
referencing the columns, not the rows... As a general rule you should alway
reference bot dimensions of the array to avoid any confusion... because it
certainly can be confusing...

HTH

"Jeremy Gollehon" wrote:

Can someone explain this to me?

From the immediate window:
?Range("A1").Item(3,1).address
$A$3
?Range("A1").Item(3).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3,1).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3).address
$C$1 <----!!!???

The last one there is where my confusion lies.

I'm sorting a range with the code below(rough example):
---------------------------------------------------------------------------------------------
Set rDataRng = Range(Range("A1"), Range("G10"))
With rDataRng
.Value = .Value
.Sort Key1:=.Item(2, 1), Order1:=xlDescending, OrderCustom:=1, _
Orientation:=xlLeftToRight
End With
---------------------------------------------------------------------------------------------

I initially had .Item(2) in there as the Key1 entry, which caused me to
stumble upon this (what I see as) strange behavior.
Is this a bug or one of those "by design" features?

Thanks for any input.
-Jeremy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Strange Range.item behavior?

Jim, and Jeremy,

The arguments are not read right to left, and singel indices are not
referring to rows or columns. (They just seem to sometimes, when working
with single column or single row ranges). Excel steps through rows first
when simply indexing a range.

MsgBox Range("A1:Z10000").Item(100000).Address

works, because the 100000 doesn't refer to a column or a row, but rather the
100000th member when stepping through rowwise.

HTH,
Bernie
MS Excel MVP


"Jim Thomlinson" wrote in message
...
You are only referencing one dimension of a two dimension array. Arguments
are read right to left (backwards from what you would think) so you are
referencing the columns, not the rows... As a general rule you should

alway
reference bot dimensions of the array to avoid any confusion... because it
certainly can be confusing...

HTH

"Jeremy Gollehon" wrote:

Can someone explain this to me?

From the immediate window:
?Range("A1").Item(3,1).address
$A$3
?Range("A1").Item(3).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3,1).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3).address
$C$1 <----!!!???

The last one there is where my confusion lies.

I'm sorting a range with the code below(rough example):


--------------------------------------------------------------------------

-------------------
Set rDataRng = Range(Range("A1"), Range("G10"))
With rDataRng
.Value = .Value
.Sort Key1:=.Item(2, 1), Order1:=xlDescending, OrderCustom:=1, _
Orientation:=xlLeftToRight
End With


--------------------------------------------------------------------------

-------------------

I initially had .Item(2) in there as the Key1 entry, which caused me to
stumble upon this (what I see as) strange behavior.
Is this a bug or one of those "by design" features?

Thanks for any input.
-Jeremy





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Strange Range.item behavior?

Not exactly

? Range(Range("A1"), Range("G10")).Item(8).address
$A$2


--
Regards,
Tom Ogilvy

"Jim Thomlinson" wrote in message
...
You are only referencing one dimension of a two dimension array. Arguments
are read right to left (backwards from what you would think) so you are
referencing the columns, not the rows... As a general rule you should

alway
reference bot dimensions of the array to avoid any confusion... because it
certainly can be confusing...

HTH

"Jeremy Gollehon" wrote:

Can someone explain this to me?

From the immediate window:
?Range("A1").Item(3,1).address
$A$3
?Range("A1").Item(3).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3,1).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3).address
$C$1 <----!!!???

The last one there is where my confusion lies.

I'm sorting a range with the code below(rough example):


--------------------------------------------------------------------------

-------------------
Set rDataRng = Range(Range("A1"), Range("G10"))
With rDataRng
.Value = .Value
.Sort Key1:=.Item(2, 1), Order1:=xlDescending, OrderCustom:=1, _
Orientation:=xlLeftToRight
End With


--------------------------------------------------------------------------

-------------------

I initially had .Item(2) in there as the Key1 entry, which caused me to
stumble upon this (what I see as) strange behavior.
Is this a bug or one of those "by design" features?

Thanks for any input.
-Jeremy





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Strange Range.item behavior?

Thanks for the clarification Bernie. Thinking about this more sparked my
memory of where I first learned to use .item.
http://www.cpearson.com/excel/cells.htm

Low and behold, right there in the article:
--------------------------------------------------------------------------
Cells can also be referenced with a single index number. The counting goes
left to right, then down one row and left to right again. E.g.,
Range("A1:B2")(1) refers to Cell A1
Range("A1:B2")(2) refers to Cell B1
Range("A1:B2")(3) refers to Cell A2
Range("A1:B2")(4) refers to Cell B2
--------------------------------------------------------------------------

Thanks to Jim and Bernie for your replies.
-Jeremy



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Jim, and Jeremy,

The arguments are not read right to left, and singel indices are not
referring to rows or columns. (They just seem to sometimes, when working
with single column or single row ranges). Excel steps through rows first
when simply indexing a range.

MsgBox Range("A1:Z10000").Item(100000).Address

works, because the 100000 doesn't refer to a column or a row, but rather
the
100000th member when stepping through rowwise.

HTH,
Bernie
MS Excel MVP


"Jim Thomlinson" wrote in
message
...
You are only referencing one dimension of a two dimension array.
Arguments
are read right to left (backwards from what you would think) so you are
referencing the columns, not the rows... As a general rule you should

alway
reference bot dimensions of the array to avoid any confusion... because
it
certainly can be confusing...

HTH

"Jeremy Gollehon" wrote:

Can someone explain this to me?

From the immediate window:
?Range("A1").Item(3,1).address
$A$3
?Range("A1").Item(3).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3,1).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3).address
$C$1 <----!!!???

The last one there is where my confusion lies.

I'm sorting a range with the code below(rough example):


--------------------------------------------------------------------------

-------------------
Set rDataRng = Range(Range("A1"), Range("G10"))
With rDataRng
.Value = .Value
.Sort Key1:=.Item(2, 1), Order1:=xlDescending, OrderCustom:=1, _
Orientation:=xlLeftToRight
End With


--------------------------------------------------------------------------

-------------------

I initially had .Item(2) in there as the Key1 entry, which caused me to
stumble upon this (what I see as) strange behavior.
Is this a bug or one of those "by design" features?

Thanks for any input.
-Jeremy









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Strange Range.item behavior?

Yep, posted 7 years ago. Nice to see it still referred to, thanks to
Chip Pearson's inclusion of it on his Web site.

Alan Beban

Jeremy Gollehon wrote:
Thanks for the clarification Bernie. Thinking about this more sparked my
memory of where I first learned to use .item.
http://www.cpearson.com/excel/cells.htm

Low and behold, right there in the article:
--------------------------------------------------------------------------
Cells can also be referenced with a single index number. The counting goes
left to right, then down one row and left to right again. E.g.,
Range("A1:B2")(1) refers to Cell A1
Range("A1:B2")(2) refers to Cell B1
Range("A1:B2")(3) refers to Cell A2
Range("A1:B2")(4) refers to Cell B2
--------------------------------------------------------------------------

Thanks to Jim and Bernie for your replies.
-Jeremy



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...

Jim, and Jeremy,

The arguments are not read right to left, and singel indices are not
referring to rows or columns. (They just seem to sometimes, when working
with single column or single row ranges). Excel steps through rows first
when simply indexing a range.

MsgBox Range("A1:Z10000").Item(100000).Address

works, because the 100000 doesn't refer to a column or a row, but rather
the
100000th member when stepping through rowwise.

HTH,
Bernie
MS Excel MVP


"Jim Thomlinson" wrote in
message
...

You are only referencing one dimension of a two dimension array.
Arguments
are read right to left (backwards from what you would think) so you are
referencing the columns, not the rows... As a general rule you should


alway

reference bot dimensions of the array to avoid any confusion... because
it
certainly can be confusing...

HTH

"Jeremy Gollehon" wrote:


Can someone explain this to me?

From the immediate window:
?Range("A1").Item(3,1).address
$A$3
?Range("A1").Item(3).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3,1).address
$A$3
?Range(Range("A1"), Range("G10")).Item(3).address
$C$1 <----!!!???

The last one there is where my confusion lies.

I'm sorting a range with the code below(rough example):

--------------------------------------------------------------------------


-------------------

Set rDataRng = Range(Range("A1"), Range("G10"))
With rDataRng
.Value = .Value
.Sort Key1:=.Item(2, 1), Order1:=xlDescending, OrderCustom:=1, _
Orientation:=xlLeftToRight
End With

--------------------------------------------------------------------------


-------------------

I initially had .Item(2) in there as the Key1 entry, which caused me to
stumble upon this (what I see as) strange behavior.
Is this a bug or one of those "by design" features?

Thanks for any input.
-Jeremy







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
Strange behavior Ritchie Excel Discussion (Misc queries) 2 September 26th 06 02:21 AM
Strange behavior DeRussie Setting up and Configuration of Excel 4 November 26th 05 05:41 PM
Strange behavior. Wiley Coyote Excel Discussion (Misc queries) 7 October 18th 05 04:35 PM
Strange PrintOut Behavior Bob Nonnemann Excel Programming 1 April 22nd 04 06:22 PM
Help with very strange cell behavior Terry von Gease Excel Programming 10 August 29th 03 04:21 PM


All times are GMT +1. The time now is 09:40 AM.

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"