When is a Loop Necessary ?


G

Guest

When is it necessary to loop over the cells in a range as opposed to setting
some property of the entire range at once. For example:

Sub loop_test()
Dim rr As Range, r As Range
Set rr = Range("A1,C10,D12")
For Each r In rr
r.Value = r.Address
Next
End Sub


can be accomplished with:

Sub loop_test2()
Dim rr As Range
Set rr = Range("A1,C10,D12")
rr.Value = rr.Address
End Sub
 
Ad

Advertisements

G

Guest

Was that a philosophical question? A loop may be more practical, efficient
and useful to speed up repetitive comparisions or to perform repetitive
commands, but necessary implies that there is no other way. <g>
 
Ad

Advertisements

G

Guest

JE & Alan:

You are both correct. The difference in the results shows the error in my
thinking

Thanks for replying.
 

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