# Infinite loop

#### xenedra13

##### Board Regular
This sub is creating an infinite loop. I have no idea why or how to fix it. Any help would be greatly appreciated!
Code:
``````For i = 1 To 51
For r = 6 To 57

Workbooks(Margin).Worksheets(Sheets(i) & Graph1).Activate
Range(HL1).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 4)
Range(HL2).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 5)
Range(HL3).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 6)
Range(CTD1).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 7)
Range(CTD2).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 8)
Range(CTD3).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 9)

Workbooks(Margin).Activate
Worksheets(Sheets(i) & Graph2).Activate
Range(RLPC1).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 10)
Range(RLPC2).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 11)
Range(CRLPC1).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 12)
Range(CRLPC2).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 13)

Workbooks(Margin).Activate
Worksheets(Sheets(i) & Graph3).Activate
Range(NI1).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 14)
Range(NI2).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 15)
Range(CNI1).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 16)
Range(CNI2).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 17)

Workbooks(Margin).Activate
Worksheets(Sheets(i) & Graph4).Activate
Range(PC1).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 18)
Range(PC2).Copy Workbooks(Control).Worksheets("Margin Emails").Cells(r, 19)

Workbooks(Control).Activate

Next r
Next i``````

### Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If this is in an Event procedure you need to set Application.enableevents to false then reset to true at the end

If this is in an Event procedure you need to set Application.enableevents to false then reset to true at the end
I did that. Didn't change anything. I reran it and figured out that it isn't actually infinite, it's just a lot longer than it needs to be. It runs the same client 52 times instead of once and then does that for each of the 52 clients. So it's 52 times longer than it should be.

Replies
6
Views
990
Replies
3
Views
610
Replies
0
Views
576
Replies
10
Views
730
Replies
0
Views
558

1,221,185
Messages
6,158,406
Members
451,490
Latest member
desktopace

### 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.

### Which adblocker are you using?

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

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