As mentioned, you can only Hide multiple sheets without a loop, like in this statement:
Worksheets(Array(1,2,3,4,5,6,7,8,9,10,11,...,200)).Visible = True
but Unhiding multiple sheets requires the loop
However, there is a much faster method available for this, using Custom Views (in View Tab)
The code bellow generates 2 views 1. "ShowAllWs", and 2. "HideAllWs"
Performance wise:
For 201 Worksheets
Loop HideAll - Time: 0.039 sec (initial setup - sets array, except one Ws in one operation)
Loop ShowAll - Time: 0.648 sec (initial setup - unhides all using a loop)
View ShowAll - Time: 0.023 sec (consecutive runs - no loop)
View HideAll - Time: 0.023 sec (consecutive runs - no loop)
Option Explicit
Public Sub SetWsVisibility(Optional ByVal vis As Boolean = False, _
Optional ByVal visibleWs As Long = 0)
Static vSet As Boolean, hSet As Boolean, wsCount As Long, lastV As Long, i As Long
With ThisWorkbook
wsCount = .Worksheets.Count - 1
'if visibleWs is 0 last ws is visible, or use any other valid sheet index
visibleWs = IIf(visibleWs < 1 Or visibleWs > wsCount, wsCount + 1, visibleWs)
If wsCount <> .Worksheets.Count - 1 Or visibleWs <> lastV Then
vSet = False
hSet = False
Else
If vSet And vis Then .CustomViews("ShowAllWs").Show: Exit Sub
If hSet And Not vis Then .CustomViews("HideAllWs").Show: Exit Sub
End If
Application.ScreenUpdating = False
If vis Then
For i = 1 To wsCount + 1
With .Worksheets(i)
If Not .Visible Then .Visible = vis
End With
Next
.Worksheets(1).Activate
.CustomViews.Add ViewName:="ShowAllWs" 'Save View (one-time operation)
vSet = True
Else
If visibleWs <> lastV Then
For i = 1 To wsCount + 1
With .Worksheets(i)
If Not .Visible Then .Visible = 1
End With
Next
End If
Dim arr() As Variant, j As Long
ReDim arr(1 To wsCount)
j = 1
For i = 1 To wsCount + 1
If i <> visibleWs Then arr(j) = i Else j = j - 1
j = j + 1
Next
.Worksheets(arr).Visible = vis
.CustomViews.Add ViewName:="HideAllWs" 'Save View (one-time operation)
hSet = True
lastV = visibleWs
End If
Application.ScreenUpdating = True
End With
End Sub
To call it use this:
Public Sub UpdateWsVisibility()
SetWsVisibility 0, 5 'or 0 to hide them (or True / False respectively)
End Sub
ThisWorkbook.Worksheets(Array("Sheet1","Sheet2",etc)).Visible = xlSheetHidden
. You may want to disable screenupdate, pause calculation , disable events before setting it to hidden. – PatricK