Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default end with loop question

WIll the following work correctly?
Dim rng as Range
set rng = Range(o2:M5)
DoThis: with rng
do something until the ActiveCell goes outside "rng"
ActiveCell.offset(1).select
goto DoThis
End With
Gets here when the ActiveCell is outside of "rng"

If not, please suggest a method to control execution while ActiveCell is
within a range.

TIA
Lee Hunter

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default end with loop question

Don't work with the activecell. It is slow and causes the screen to move.

Dim cell as Range
for each cell in Range("O2:M5")


Next

where you would use ActiveCell, use cell.

--
Regards,
Tom Ogilvy


"Lee Hunter" wrote in message
...
WIll the following work correctly?
Dim rng as Range
set rng = Range(o2:M5)
DoThis: with rng
do something until the ActiveCell goes outside "rng"
ActiveCell.offset(1).select
goto DoThis
End With
Gets here when the ActiveCell is outside of "rng"

If not, please suggest a method to control execution while ActiveCell is
within a range.

TIA
Lee Hunter



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default end with loop question

Try something like this:

Sub test()

Dim rng As Range
Dim c As Range

Set rng = Range("A1:E5")
Set c = Cells(1)

c.Select

Do While Not Intersect(rng, c.Offset(1, 0)) Is Nothing
Set c = c.Offset(1, 0)
c.Select
Loop

End Sub

Lookup the Intersect method in the help.

RBS

"Lee Hunter" wrote in message
...
WIll the following work correctly?
Dim rng as Range
set rng = Range(o2:M5)
DoThis: with rng
do something until the ActiveCell goes outside "rng"
ActiveCell.offset(1).select
goto DoThis
End With
Gets here when the ActiveCell is outside of "rng"

If not, please suggest a method to control execution while ActiveCell is
within a range.

TIA
Lee Hunter


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
Loop question aelewis Excel Discussion (Misc queries) 2 October 24th 07 08:12 PM
Loop question N.F[_2_] Excel Discussion (Misc queries) 0 July 12th 07 08:02 PM
Loop question Rob Excel Programming 10 September 13th 05 10:50 PM
One more loop question Patti[_5_] Excel Programming 11 June 6th 04 07:14 AM
For loop question luvgreen[_3_] Excel Programming 1 February 20th 04 03:30 PM


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