Infinite loop

xenedra13

Board Regular
Joined
Aug 15, 2014
Messages
58
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If this is in an Event procedure you need to set Application.enableevents to false then reset to true at the end
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,937
Latest member
BeerMan23

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