Worksheet run time error 1004 - LoopIndex breaking down

grexcelman

Board Regular
Joined
Mar 1, 2015
Messages
50
Not sure why this is breaking but I have a spreadsheet with dozens of tabs that require updating through this macro loop. It indexes the first and last pages, 30 to 80 but once it reaches the 39th tab, it breaks. I've tried moving the potential bad tab(running it separately at times) but it doesn't change the break. Any thoughts on where this code or my spreadsheet could be getting tripped up?

Code:
Worksheets("Monthly Trend").Select

' determine current bounds
    Dim StartIndex, EndIndex, LoopIndex As Integer
    StartIndex = Sheets("Monthly Trend").Index
    EndIndex = Sheets("Transactions").Index
 
    For LoopIndex = StartIndex To EndIndex
    Sheets(LoopIndex).Select
    
       RetrieveSheet
       
    Next LoopIndex
 
Last edited:
unhide all your sheets and give it a go (on a copy)
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
There are hidden sheets in the document but I don't know why that would trip it up if I'm referencing by name the first and last sheets. ...would that throw it off regardless?
As I said in my post, you can't select a hidden sheet. Why not get rid of the Select line? Make sure your called procedure "RetrieveSheet" is written so that it does not require the sheet it operates on to be the active sheet.
 
Upvote 0
As I said in my post, you can't select a hidden sheet. Why not get rid of the Select line? Make sure your called procedure "RetrieveSheet" is written so that it does not require the sheet it operates on to be the active sheet.

Thank you both for your help. I didn't realize that I was also selecting hidden sheets which was the cause of the breakdown. I decided to move those hidden sheets to the end of the document, outside the Index range of my sheets and that did the trick. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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