Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Limit the Loop to 500 Rows

I have a macro that runs well down a column but I need to define the
Do Until
statement to stop it at row 500 and am stumped on how to do this.
Please help with this simple request. Thanks
Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Limit the Loop to 500 Rows

If you post the relevant code it would be helpful. But in general:

Dim c As Range
Set c = Range("A1")
Do Until c.Row 500
Debug.Print c.Row
Set c = c.Offset(1)
Loop

--

Vasant




"SteveF" wrote in message
...
I have a macro that runs well down a column but I need to define the
Do Until
statement to stop it at row 500 and am stumped on how to do this.
Please help with this simple request. Thanks
Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Limit the Loop to 500 Rows

Hi

For i=1 To 500
varValue=ActiveSheet.Range("A" & i).Value
Next i


Arvi Laanemets


"SteveF" wrote in message
...
I have a macro that runs well down a column but I need to define the
Do Until
statement to stop it at row 500 and am stumped on how to do this.
Please help with this simple request. Thanks
Steve



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Limit the Loop to 500 Rows

Here is the code - It still goes to the bottom of the sheet and keeps
trying to run. What have I done wrong. Thanks
Steve
Dim c As Range
Set c = Range("A1")

Range("C1").Select
Selection.End(xlDown).Select
Do Until c.Row 500
Selection.Insert Shift:=xlToRight
Selection.End(xlDown).Select
Loop
MsgBox ("Finished!")

On Sat, 25 Jun 2005 22:35:17 -0400, "Vasant Nanavati" <vasantn AT aol
DOT com wrote:

If you post the relevant code it would be helpful. But in general:

Dim c As Range
Set c = Range("A1")
Do Until c.Row 500
Debug.Print c.Row
Set c = c.Offset(1)
Loop


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Limit the Loop to 500 Rows

Hi Steve,

Since you:

Set c = Range("A1")


c.Row has a fixed value of 1 and the loop ending condition:

Do Until c.Row 500


is never met and , thus, you have a continuos loop.

Additionally, your code makes selections which are rarely necessary and
usually inefficient.

The following may do what you want - if not, post back:

Sub Tester()
Dim startCell As Range, endCell As Range
Dim rcell As Range

Set startCell = Range("C1")
Set endCell = startCell.End(xlDown)

For Each rcell In Range(startCell, endCell)
If rcell.Row 500 Then Exit For
rcell.Insert Shift:=xlToRight
Next

End Sub

---
Regards,
Norman



"SteveF" wrote in message
...
Here is the code - It still goes to the bottom of the sheet and keeps
trying to run. What have I done wrong. Thanks
Steve
Dim c As Range
Set c = Range("A1")

Range("C1").Select
Selection.End(xlDown).Select
Do Until c.Row 500
Selection.Insert Shift:=xlToRight
Selection.End(xlDown).Select
Loop
MsgBox ("Finished!")

On Sat, 25 Jun 2005 22:35:17 -0400, "Vasant Nanavati" <vasantn AT aol
DOT com wrote:

If you post the relevant code it would be helpful. But in general:

Dim c As Range
Set c = Range("A1")
Do Until c.Row 500
Debug.Print c.Row
Set c = c.Offset(1)
Loop




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
want to limit worksheet to 1000 rows instead of 65,000 GeoObject New Users to Excel 6 April 14th 07 02:15 AM
the limit on how many rows can be in one spreadsheet liz Excel Worksheet Functions 2 March 4th 05 11:29 AM
Limit search range then loop thru' each cell...a bit stuck... ste mac Excel Programming 1 December 17th 04 01:35 PM
Cannot loop through rows in C# Howard Excel Programming 2 February 5th 04 03:39 PM
Limit fill-down rows Mike Fogleman Excel Programming 2 September 24th 03 01:24 PM


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