Skip to main content

Excel Macro: Unhide All Worksheets in a Workbook

If you want to unhide all Worksheets in a Workbook at once, this simple macro makes easy work for you.

Unhide All Worksheets in a Workbook

'---------------- Modules ----------------
Sub UnhideAllWorksheets()
'Step 1:  Declare your variables
    Dim ws As Worksheet
'Step 2: Start looping through all worksheets
    For Each ws In ActiveWorkbook.Worksheets
'Step 3:  Loop to next worksheet
        ws.Visible = xlSheetVisible
    Next ws
End Sub

How This Macro Works

  1. In Step 1 declares an object called ws. This creates a memory container for each worksheet the macro loops through.
  2. In Step 2, the macro starts the looping, telling Excel to enumerate through all worksheets in this workbook.
  3. In Step 3 changes the visible state to xlSheetVisible. Then it loops back to get the next worksheet.

Most VBA code should be placed in Standard Modules unless specified.

If you see a comment '------------------ Modules------------------ in the code header that means put the code in a Standard Module. For more information, learn this course: Where should I put the Excel VBA code?

The following steps teach you how to put VBA code into a Standard Module:

  1. Activate the Visual Basic Editor by pressing ALT + F11.
  2. Right-click the project/workbook name in the Project Window.
  3. Choose Insert -> Module.
  4. Type or paste the code in the newly created module. You will probably need to change the sheet name, the range address, and the save location.
  5. Click Run button on the Visual Basic Editor toolbar.
  6. For more information, learn this course: Programming with Excel VBA

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>