![]() |
Run-time error '1004' on hiding worksheets
I have this code in
Private Sub Workbook_Open() ActiveWorkbook.Sheets("Cost&Marg_01").Activate Dim sh As Worksheet For Each sh In ActiveWorkbook.Sheets If sh.Name < "Cost&Marg_01" Then sh.Visible = False Else sh.Visible = True End If Next End Sub I get an applicaton defined or object defined error when it gets to the sh.Visible=False line. What have I improperly defined here? Brent |
Run-time error '1004' on hiding worksheets
Hi Brent,
At least one sheet must be visible. So, if no sheet named "Cost&Marg_01" exists, the reported error will occur. Check, therefore, that this sheet really does exist. Perhaps there is a subtle space or spelling difference. Providing that the named sheet does exist, your code runs without error for me and hides all other worksheets. --- Regards, Norman wrote in message oups.com... I have this code in Private Sub Workbook_Open() ActiveWorkbook.Sheets("Cost&Marg_01").Activate Dim sh As Worksheet For Each sh In ActiveWorkbook.Sheets If sh.Name < "Cost&Marg_01" Then sh.Visible = False Else sh.Visible = True End If Next End Sub I get an applicaton defined or object defined error when it gets to the sh.Visible=False line. What have I improperly defined here? Brent |
Run-time error '1004' on hiding worksheets
The sheet "Cost&Marg_01" indeed exists in the file. What else could it
be? |
Run-time error '1004' on hiding worksheets
Hi Brent,
Try running this version: Private Sub Workbook_Open() Dim sh As Worksheet ThisWorkbook.Sheets("Cost&Marg_01").Visible = True For Each sh In ThisWorkbook.Worksheets If UCase(sh.Name) < UCase("Cost&Marg_01") Then sh.Visible = False Else sh.Visible = True End If Next End Sub --- Regards, Norman wrote in message oups.com... The sheet "Cost&Marg_01" indeed exists in the file. What else could it be? |
All times are GMT +1. The time now is 05:40 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com