View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
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...