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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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