VBA to Close all worksheets But Exclude one

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
HI there,

I have a similar code that closes all worksheets that begin with "C_" (from MrExcel board).

However I am looking for a more dynamic code that will close all worksheets excluding one, this way I dont' need to keep updating the below code.
This is just a Sample the full code has 34 worksheets that need to be close, and I add new ones each day.

Is there some code that closes all worksheets excluding sheets("NAVIGATION").select

Code:
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    Sheets("BL_INPUT").Visible = False
    Sheets("BLO_INPUT").Visible = False
    Sheets("VC_INPUT").Visible = False
    Sheets("BLF_INPUT").Visible = False
    Sheets("BLCC_INPUT").Visible = False
    Sheets("TCC_INPUT").Visible = False
    Sheets("OUTLET_INPUT").Visible = False
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try

Code:
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "NAVIGATION" Then ws.Visible = xlSheetHidden
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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