Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default NonContiguous Range Iteration Bug?

If I have a noncontiguous range oRange defined as "V31:W31,Y31:Z31" and
I iterate through the cells with "For Each cell In oRange.Cells" set the
cell value to 5, everything works fine. However, if I iterate through with:
For i = 1 To 4
oRange.Cells(i).Value = 5
next i

The values go into "V31:W32"!
Why should using the index not work the same as a "for each" statement?
How do I reference the 3rd cell in the noncontiguous range without
iterating through the first 2?
I assume this is a bug...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default NonContiguous Range Iteration Bug?

observed in Office 2003

Matthew Wieder wrote:

If I have a noncontiguous range oRange defined as "V31:W31,Y31:Z31" and
I iterate through the cells with "For Each cell In oRange.Cells" set the
cell value to 5, everything works fine. However, if I iterate through
with:
For i = 1 To 4
oRange.Cells(i).Value = 5
next i

The values go into "V31:W32"!
Why should using the index not work the same as a "for each" statement?
How do I reference the 3rd cell in the noncontiguous range without
iterating through the first 2?
I assume this is a bug...


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default NonContiguous Range Iteration Bug?

Try this small test

Sub test()
Dim rng As Range
Set rng = Range("V31:W31,Y31:Z31")
MsgBox rng.Areas(2).Cells(1).Value
End Sub

You can use this without a loop to make the value 5
Range("a1:b1,d1:E1").Value = 5

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Matthew Wieder" wrote in message ...
If I have a noncontiguous range oRange defined as "V31:W31,Y31:Z31" and
I iterate through the cells with "For Each cell In oRange.Cells" set the
cell value to 5, everything works fine. However, if I iterate through with:
For i = 1 To 4
oRange.Cells(i).Value = 5
next i

The values go into "V31:W32"!
Why should using the index not work the same as a "for each" statement?
How do I reference the 3rd cell in the noncontiguous range without
iterating through the first 2?
I assume this is a bug...



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default NonContiguous Range Iteration Bug?

Certainly that works, but the idea behind using the Cells collection is
not to have to know or worry about how many cells are in each Area to
get to the 4th cell. As you have pointed out, if I can hard code it, I
don't have an issue.

Ron de Bruin wrote:

Try this small test

Sub test()
Dim rng As Range
Set rng = Range("V31:W31,Y31:Z31")
MsgBox rng.Areas(2).Cells(1).Value
End Sub

You can use this without a loop to make the value 5
Range("a1:b1,d1:E1").Value = 5


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default NonContiguous Range Iteration Bug?

Hi Matthew,

Thanks for posting in the community!

Currentlly we are performing some research on this problem, and we will reply you ASAP if we get any results!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default NonContiguous Range Iteration Bug?

Hi Matthew

AFAIK it is not possible with a Non Contiguous Range

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Matthew Wieder" wrote in message ...
Certainly that works, but the idea behind using the Cells collection is
not to have to know or worry about how many cells are in each Area to
get to the 4th cell. As you have pointed out, if I can hard code it, I
don't have an issue.

Ron de Bruin wrote:

Try this small test

Sub test()
Dim rng As Range
Set rng = Range("V31:W31,Y31:Z31")
MsgBox rng.Areas(2).Cells(1).Value
End Sub

You can use this without a loop to make the value 5
Range("a1:b1,d1:E1").Value = 5




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
Noncontiguous cell range jeffrey Excel Worksheet Functions 1 June 15th 11 06:27 PM
average of 12 noncontiguous cells goss[_2_] Excel Discussion (Misc queries) 6 November 12th 07 10:26 PM
Noncontiguous rows KC8DCN Excel Discussion (Misc queries) 3 August 18th 06 05:34 AM
noncontiguous cells Vivian Excel Discussion (Misc queries) 2 July 21st 06 01:00 AM
Non-Contiguos Range Iteration Matthew Wieder Excel Programming 8 March 4th 04 12:54 PM


All times are GMT +1. The time now is 04:22 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"