Hide all sheets but selected sheets - an example

  • Thread starter aztecbrainsurgeon
  • Start date
A

aztecbrainsurgeon

No question here, just a procedure example for the archive.

Hide all worksheets in the active workbook but the selected sheets
Credit to original poster (Bob Phillips) for code


Sub HideAllSheetsBUTSELECTEDSheets()

'Hides all worksheets in the active workbook except the
'selected worksheets

Dim sh As Worksheet
Dim fFound As Boolean
Dim groupedArr() As Variant
Dim i As Long

ReDim groupedArr(1 To ActiveWindow.SelectedSheets.Count)
For i = LBound(groupedArr) To UBound(groupedArr)
groupedArr(i) = ActiveWindow.SelectedSheets(i).Name
Next

Application.DisplayAlerts = False
For Each sh In ActiveWorkbook.Worksheets
fFound = False
For i = LBound(groupedArr) To UBound(groupedArr)
If sh.Name = groupedArr(i) Then
fFound = True
Exit For
End If
Next i
' If Not fFound Then sh.Delete ' use this row for deletes
If Not fFound Then sh.Visible = xlSheetHidden

Next
Application.DisplayAlerts = True

End Sub

Search criteria
hide all sheets but selected hide ungrouped sheets show only grouped
sheets
Compare worksheet groups compare sheet groups
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top