LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default For Each with Range object in Excel 97 SR-2

Hi all,

I am ashamed not to know why this doesn't work... I am
using old Excel 97 SR-2.

The following code happily goes through each cell in the
range from A1 to A5, and prints each address.

Dim rngSELECT As Range
Dim rngRange As Range
Set rngSELECT = Range("A1:A5")

For Each rngRange In rngSELECT
Debug.Print rngRange.Address
Next rngRange

But, if I try to do the following:

Dim rngSELECT As Range
Dim rngRange As Range
With Range("AddSELECT")
Set rngSELECT = .Resize(.Rows.Count - 1, 1).Columns
(1) 'returns $B$17:$B$226
End With

For Each rngRange In rngSELECT
Debug.Print rngRange.Address
Next rngRange

The above "For Each" loop is executed only once and gets
out!!! "Set rngSELECT" sets the rngSELECT to $B$17:$B$226
before "For Each". On the first execution of "For Each"
loop, rngRange.Address somehow returns the whole
$B$17:$B$226!!! Why does it NOT return a single cell
(address)??? I expect its address to be $B$17.

I looked at some previous posts and it might be a problem
to use collection in "For Each" loop in Excel 97...

Thanks for your time,
---
Tetsuya Oguma, Sydney, Australia
 
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
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Excel 97 - Clear Method Of Range Object Failed Dave Peterson[_3_] Excel Programming 2 September 26th 03 01:56 AM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM
Range object to Array object conversion Alan Beban[_3_] Excel Programming 0 August 1st 03 01:24 AM
Range object to Array object conversion Tom Ogilvy Excel Programming 0 August 1st 03 12:16 AM


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

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

About Us

"It's about Microsoft Excel"