Problem with Loops

chrgrose

Board Regular
Joined
Sep 11, 2009
Messages
80
Code:
Sub runner()
Dim a As Long

For a = 1 To 12 Step 1
  "Do something"
  Loop
Next a

End Sub
How do this task 100 times without repeating the whole "For..." code? Right now I have a sheet like this and the only way I can keep it running is if I manually run it over and over. I've tried to nest this loop in another loop but it acts like it can't redo the loop if it's already been performed.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
It's hard to say without seeing the actual code you're trying to use, and not a simplified example.

Are you trying to do a loop within a loop?

Try something like

Rich (BB code):
For a = 1 to 12
   'This line is executed only 12 times (each loop of a)
    For b = 1 to 100
       'This line is executed a total of 1200 times
       '100 loops of b X 12 loops of a
    Next b
Next a
 
Upvote 0

Forum statistics

Threads
1,222,383
Messages
6,165,665
Members
451,983
Latest member
Raph24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top