top of page

VBA CODE: Hide Unhide Sheets | Microsoft Excel

Updated: Mar 14, 2021

If you have too many worksheets in an excel workbook and want to hide some of the sheets or you just don't want others to see some particular sheets when they open your file, you can use the below VBA code to hide and unhide many sheets in one go.


VBA Code: Hide Sheet(s)

The below code will hide only those worksheets for which you code and require you to specify the sheet name within the VBA code. It should be specified inside the brackets with double quotes as shown below.

Sub HideSheets()
    Worksheets("Sheet2").Visible = False
    Worksheets("Sheet3").Visible = False
End Sub

VBA Code: Unhide Sheet(s)

The below code will unhide only those worksheets for which you code and require you to specify the sheet name within the VBA code. It should be specified inside the brackets with double quotes as shown below.

Sub UnhideSheets()
    Worksheets("Sheet2").Visible = True
    Worksheets("Sheet3").Visible = True
End Sub

VBA Code: Hide All Other Sheets

The below code will hide all the worksheets other than the active worksheet. No need to code individually for all the worksheets.

Sub HideAllOtherSheet()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> ThisWorkbook.ActiveSheet.Name Then
    ws.Visible = False
    End If
    Next ws
End Sub

VBA Code: Unhide All Sheets

The below code will unhide all the worksheets which are already hidden in the workbook. No need to code individually for all the worksheets.

Sub UnhideAllSheets()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    ws.Visible = True
    Next ws
End Sub


Important Considerations:

  • Sheet name such as "Sheet2" and "Sheet3" can be replaced as per the requirement and can repeat the line if there are more number of sheets involved.

Disclaimer: We, in our example, only cover how to perform such functions in excel and less focusing on the type of example we take. Our motive is to deliver the exact solution to the queries on "How To" in the most simplest way. Of course, the application of these function can be seen in our advanced modules with more complex examples and datasets.

Feel free to share your views and ask for models in the #comment section. If you like our content, please hit a #like button.

 
 
 

Comments


bottom of page