RANGE & NESTED LOOPS

J

jay dean

I have three questions ----

(1)Does the range mycell after the "Each" in
For Each mycell in SomeRange
always have to refer to one cell at a time in SomeRange?
If not, if I wanted mycell to refer to a range consisting of multiple
cells in SomeRange, how do I do that?

(2)In general, when dealing with nested looping constructs how do I
determine which loop is the inner loop and which is the outer? I
sometimes have a problem with picturing how to construct nested
loops.Any tips or aids or recommendations which would assist me picture
and easily construct nested loops would be appreciated.

(3) Lastly, what's the difference between
myrange=0 and myrange.value=0

Thanks.
Jay Dean
 
C

Chip Pearson

Jay,

1) Under most circumstances, mycell will refer to a single cell.
To be sure use
For Each mycell In SomeRange.Cells

2) Indentation is the easiest way to tell what code is in what
loop.

3) There is no difference. Value is the default property of
Range, so you may leave off the .Value if you so desire. I
usually include it for clarity.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top