ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code loops 1024 times not what i ask (https://www.excelbanter.com/excel-programming/336605-code-loops-1024-times-not-what-i-ask.html)

Rob Hargreaves[_2_]

code loops 1024 times not what i ask
 
Hi

I wonder if someone can help, I am trying to repeat some code 200 times can
you tell me where I am going wrong in my loop.

(It is doing 1024 times!)

Sub test()
Dim x As Integer

Do Until x = 200
'code to repeat
x = x + 1
Loop

End Sub

thanks for your help.

Rob




Norman Jones

code loops 1024 times not what i ask
 
Hi Rob,

Your code works for me.

To test it, I changed:

x = x + 1

to

x = x + 1
Debug.Print x

What final value do you get in the intermediate window if you add the debug
line?

---
Regards,
Norman



"Rob Hargreaves" wrote in message
...
Hi

I wonder if someone can help, I am trying to repeat some code 200 times
can you tell me where I am going wrong in my loop.

(It is doing 1024 times!)

Sub test()
Dim x As Integer

Do Until x = 200
'code to repeat
x = x + 1
Loop

End Sub

thanks for your help.

Rob





Ron de Bruin

code loops 1024 times not what i ask
 
Try it like this

Sub test()
Dim x As Integer
x = 0
Do Until x = 200
'code to repeat
x = x + 1
Loop
MsgBox x
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Rob Hargreaves" wrote in message ...
Hi

I wonder if someone can help, I am trying to repeat some code 200 times can you tell me where I am going wrong in my loop.

(It is doing 1024 times!)

Sub test()
Dim x As Integer

Do Until x = 200
'code to repeat
x = x + 1
Loop

End Sub

thanks for your help.

Rob





Rob Hargreaves[_2_]

code loops 1024 times not what i ask
 
Hi thanks for your responses guys.

I have tried to add the msgbox and it does display the correct number.

The code i am using selects all then copies the selection and I was
including this in my loop!

Now moved it works as it should.

Thanks again

Rob



"Rob Hargreaves" wrote in message
...
Hi

I wonder if someone can help, I am trying to repeat some code 200 times
can you tell me where I am going wrong in my loop.

(It is doing 1024 times!)

Sub test()
Dim x As Integer

Do Until x = 200
'code to repeat
x = x + 1
Loop

End Sub

thanks for your help.

Rob








All times are GMT +1. The time now is 06:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com