Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Run-time error '1004' on hiding worksheets

The sheet "Cost&Marg_01" indeed exists in the file. What else could it
be?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error 1004 while conditionally hiding rows as a result ofworksheet protection ran58 Excel Discussion (Misc queries) 2 July 22nd 09 07:42 AM
1004 Error when hiding/unhiding rows ianb Excel Discussion (Misc queries) 5 March 27th 08 08:42 AM
Run-Time error '1004' [email protected] Excel Discussion (Misc queries) 3 March 29th 06 08:13 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
Run-time error 1004 JimFor Excel Programming 4 December 14th 04 10:19 PM


All times are GMT +1. The time now is 01:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"