I am working with a loop that is switching worksheets every 30 seconds. After the worksheet loops through 300 times, I need it to call a macro; however, the additional macro takes 5 minutes to run.
I need to be able to call the macro and adjust the timer to account for the 5 minute interval. I believe that the macro is crashing because it does not know how to get back to the proper sheet that should be loaded as so much time has passed. How can I increase the amount of time that is needed for the additional macro? Here is a block of the code that I am working with:
For j = 1 To Loops 'This counts the number of loops executed
For i = 1 To 5 'There are 5 pages in the worksheet
Worksheets(i).Select 'Select the next worksheet
x = Timer
While Timer - x < Pause 'This does the pausing
DoEvents
Wend
If i = 1 And j = 300 Then Call Refresh 'When this completes, the macro crashes. Refresh is the name of the Macro.
I have tried adding in additional If Then statements to try updating and then returning the Timer count from 5 to 300 and then back to 5, but get error 91 runtime errors. These are the additional If Then Statements that I added. If i = 2 And j = 1 Then Pause = 300 'This would set the pause timer for this event to 5 minutes and If i = 3 And j = 1 Then Pause = 5 'This should reset the timer back to 5 seconds