Hide/ Unhide - xlSheetVeryHidden

NSN_VBA

New Member
Joined
Aug 3, 2018
Messages
7
Hi,

I am looking to hide an array of worksheets as shown below;

Worksheets(Array("Data Log", "Rev. History", "Visual Set Point")).Visible = False

This works great to hide the worksheets, however what I am really looking to do is, very hide the worksheets, something like this;

Worksheets(Array("Data Log", "Rev. History", "Visual Set Point")).Visible = xlSheetVeryHidden

This doesn't work so great!

If anyone can let me know a better way for writing this code that'll be great
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
Code:
   Dim ws As Worksheet
   
   For Each ws In Sheets(Array("Data Log", "Rev. History", "Visual Set Point"))
      ws.Visible = 2
   Next ws
 
Upvote 0
Mate you're an absolute legend! That works great.

In addition to this, I am also having troubles. If all worksheets are already hidden I get a;

Run-time error '1004':

Method 'Visible' of object'_Worksheet' failed

How do I check whether all worksheets are visible before running this code?
 
Upvote 0
You shouldn't get that error.
Is your workbook protected?
 
Upvote 0
Hi, yes I protect it when I hide it, and unprotect it when I unhide it. I tried turning off the protection and it works great, but I will need the protection on.

Maybe an IF something?

Here's my complete code;

Option Explicit


Sub HideSheets()

Dim ws As Worksheet


For Each ws In Sheets(Array("Data Log", "Rev. History", "Visual Set Point"))
ws.Visible = xlSheetVeryHidden
Next ws


ActiveWorkbook.Protect Password:="Calculator", Structure:=True


End Sub


Sub UnhideSheets()


Dim ws As Worksheet


ActiveWorkbook.Protect Password:="Calculator", Structure:=False


For Each ws In Sheets(Array("Data Log", "Rev. History", "Visual Set Point"))
ws.Visible = xlSheetVisible
Next ws


wsDashboard.Unprotect "Calculator"
wsDataLog.Unprotect "Calculator"
wsVisualSetPoint.Unprotect "Calculator"

End Sub
 
Upvote 0
Unprotect the workbook first like
Code:
Sub HideSheets()
   Dim ws As Worksheet
   ActiveWorkbook.Unprotect "Calculator"
   For Each ws In Sheets(Array("Pcode", "MA", "Fluff"))
      ws.Visible = 2
   Next ws
   ActiveWorkbook.Protect Password:="Calculator", Structure:=True
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,288
Members
448,885
Latest member
LokiSonic

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