Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in selecting a sheet using vba

Status
Not open for further replies.

Mack2

Instructor
Mar 12, 2003
336
US
I have simple code that selects all the sheets within a workbook. It works in one workbook, but when I copy it to another workbook I get an error saying method out of range. Is there a setting within the workbook that could be causing this. Thanks for your help!!!

For I = 2 To Sheets.Count
Sheets(I).Select
'FormatReport
Next I
 
you have multiple sheets - in response to Skip?
or you have multiple hidden sheets?

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Any chartsheets or older type sheets (dialogs etc.) that FormatRecord macro can't cope with? If so, use Worksheets instead Sheets collection.

combo
 
No hidden sheets. In the workbook that the code works, the code is in a module. In the workbook that is does not work, the code is in a spreadsheet module. Could scope be an issue? THANKS FOR YOUR HELP
 
Not too sure
I've just tried by adding the code to a sheet module as stand alone code and it worked ok (as would be expected really) then tried adding it to the selection change event and fired it that way - still worked!

Is your code fired from an event and if so which one?

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top