loop a specific number of occurrences

  • Thread starter Thread starter paularo
  • Start date Start date
P

paularo

How do I get a "do loop" to run a specific number of times then stop?

Thanks.
 
For 10 times:

Sub dural()
i = 1
Do While i < 11
' do some stuff
i = i + 1
Loop
End Sub
 
try this
'======================
dim doloop as long

doloop = 1

do until doloop = 3
'your code
doloop = doloop+1
loop
'=======================
worked for me
:)
susan
 
Typically, one would use a For loop, not a Do loop, in this
circumstance. E.g.,

Dim N As Long
For N = 1 To 10
' do something
Next N

However, if you do want a Do loop, use

N = 0
Do Until N = 10
' do something
N = N + 1
Loop

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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

Back
Top