Redo Loop?

chrgrose

Board Regular
Joined
Sep 11, 2009
Messages
80
I have the code

Code:
Option Explicit
Sub runner()
Dim a, b, c, starta, startb, startc As Long
starta = 11
startb = 11

Do Until Range(Cells(5, 1), Cells(5, 1)) > 3
For b = startb To 12 Step 1

For a = starta To 12 Step 1
  Do Until Range(Cells(2, 1), Cells(2, 1)) > a
    Range(Cells(2, 1), Cells(2, 1)).CalculateRowMajorOrder
  Loop
Next a
  Do Until Range(Cells(3, 1), Cells(3, 1)) > b
    Range(Cells(3, 1), Cells(3, 1)).CalculateRowMajorOrder
  Loop
Next b
Range(Cells(5, 1), Cells(5, 1)).CalculateRowMajorOrder
a = starta
b = startb
Loop

End Sub
The above code is supposed to execute what is nested beneath For a, and For b, then perform one calculation on "Range(Cells(5, 1), Cells(5, 1))", then reset the values of a and b back to their initial values. I would think that this would mean that for the next loop, since a and b are reset, the For a and For b tasks will be performed again, but it looks like it is skipping over it and it just performs three more calculations on "Range(Cells(5, 1), Cells(5, 1))" and is done.

Am I approaching this wrong? I want the For a and For b codes to be performed again each time do "Range(Cells(5, 1), Cells(5, 1)).CalculateRowMajorOrder".
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
do you know how to use <F8> to step through your code execution? that should tell you whats wrong with your logic
 
Upvote 0
I don't know how executing these tasks would be logical without having the tasks nested like this. The "For a..." and "For b..." loops need to be performed in a loop.
 
Upvote 0
Let me make my question simpler, since I still can't figure out how to solve my problem:
Code:
Sub runner()
Dim ac 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?
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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