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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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