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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
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
 

NSN_VBA

New Member
Joined
Aug 3, 2018
Messages
7
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
You shouldn't get that error.
Is your workbook protected?
 

NSN_VBA

New Member
Joined
Aug 3, 2018
Messages
7
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,332
Office Version
365
Platform
Windows
Glad to help & thanks for the feedback
 

Forum statistics

Threads
1,082,359
Messages
5,364,916
Members
400,815
Latest member
Joaquin Phoenix

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top