Closing (Hiding) multiple visible tabs.

jmk15315

Board Regular
Joined
Nov 7, 2021
Messages
73
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
I know how to close (Hide) a tab or multiple tabs by using either the "sheet" name or the sheet identifier. What I am wondering is if there is a way to close all open (unhidden) tabs with the exception of a specific tab or tabs?

For example, I can close a tab by being in that tab and using "ALT,O,H,H" or inside my vba "Activesheet.Visible=Hidden" or "Sheet20.Visible=Hidden"

What I am hoping to do is provide a macro that closes all unhidden tabs with the exception of three (2) tabs. Essentially resetting the workbook back to a starting point.

Any direction would be helpful.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
VBA Code:
Sub hideMain()
    Dim sheetNamestoSkip() As Variant
    sheetNamestoSkip = Array("Sheet1", "Sheet2")
    hideemall sheetNamestoSkip
    Erase sheetNamestoSkip
End Sub

Sub hideemall(sheetNamestoSkip() As Variant)
    Dim toSkip As String
    toSkip = "," & Join(sheetNamestoSkip, ",") & ","
    Dim sh As Worksheet
    For Each sh In ThisWorkbook.Worksheets
        If sh.Visible Then
            If Not toSkip Like "*," & sh.Name & ",*" Then
                sh.Visible = xlSheetHidden
            End If
        End If
    Next sh
    Set sh = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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