Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default When is a Loop Necessary ?

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
--
Gary''s Student - gsnu200747
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default When is a Loop Necessary ?

You only need to loop when you have to test values in each cell for some
condition.



"Gary''s Student" wrote:

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
--
Gary''s Student - gsnu200747

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default When is a Loop Necessary ?

Thank you!
--
Gary''s Student - gsnu200747


"Joel" wrote:

You only need to loop when you have to test values in each cell for some
condition.



"Gary''s Student" wrote:

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
--
Gary''s Student - gsnu200747

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default When is a Loop Necessary ?

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

"Gary''s Student" wrote:

Thank you!
--
Gary''s Student - gsnu200747


"Joel" wrote:

You only need to loop when you have to test values in each cell for some
condition.



"Gary''s Student" wrote:

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
--
Gary''s Student - gsnu200747

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default When is a Loop Necessary ?

No it can't.

Alan Beban

Gary''s Student wrote:
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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default When is a Loop Necessary ?

????

The two routines return different results...


In article ,
Gary''s Student wrote:

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default When is a Loop Necessary ?

JE & Alan:

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

Thanks for replying.
--
Gary''s Student - gsnu200747


"JE McGimpsey" wrote:

????

The two routines return different results...


In article ,
Gary''s Student wrote:

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


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
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 0 March 27th 07 11:17 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


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