Hide / Unhide worksheets

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
767
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I think this maybe a simple one, but I have no idea why an error has started suddenly when the code below works in another sheet

I have 2 subs() 1 to hide and 1 to unhide, but I am getting a 'Run-timer error '1004': Application-defined or object-defined error" and I am lost with it.
even if I change the xlVeryHidden to True I still get the same error.

Code:
Private Sub RevealSheets()
    Sheet1.Visible = True
    Sheet2.Visible = True
    Sheet3.Visible = True
    Sheet4.Visible = True
    Sheet5.Visible = True
    Sheet6.Visible = True
    Sheet7.Visible = True
    
       Sheets("Welcome Page").Select
End Sub
Private Sub HideSheets()

    
    Sheet1.Visible = xlVeryHidden
    Sheet2.Visible = xlVeryHidden
    Sheet3.Visible = True
    Sheet4.Visible = xlVeryHidden
    Sheet5.Visible = xlVeryHidden
    Sheet6.Visible = xlVeryHidden
    Sheet7.Visible = xlVeryHidden
    
        Sheets("Welcome Page").Select
End Sub

Any idea what I am doing wrong, thanks in advance
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Do all sheets 1-7 exist in the workbook you're trying to use this on? What line does it error out on?
 
Upvote 0
Hi,

You should be able to perform both operations within one code

Untested but try this update & see if does what you want

VBA Code:
Sub HideSheets(ByVal SheetVisible As XlSheetVisibility)
    Dim ws As Worksheet
    
    With Worksheets("Welcome Page")
        .Visible = xlSheetVisible
        .Select
     End With
     
     Sheet3.Visible = xlSheetVisible
     
    For Each ws In Worksheets(Array(Sheet1.Name, Sheet2.Name, Sheet4.Name, Sheet5.Name, Sheet6.Name, Sheet7.Name))
        ws.Visible = SheetVisible
    Next
End Sub

Call the code & pass required argument (which you can select from the IntelliSense)

VBA Code:
 HideSheets xlSheetVisible

or

VBA Code:
 HideSheets xlSheetVeryHidden

Dave
 
Upvote 0
I think this maybe a simple one, but I have no idea why an error has started suddenly when the code below works in another sheet
Do you only have problems with sheet3?
You can share your file for review.

You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,232
Members
449,092
Latest member
SCleaveland

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