Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA: Unhide a Hidden Sheet Step by Step

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You unhide a sheet in Excel VBA with one line of code: Worksheets("SheetName").Visible = xlSheetVisible. Replace SheetName with the tab name in quotes, or use the sheet's code name for a version that keeps working if the tab is renamed. Run it from a normal module or the Immediate window, and the tab reappears in the workbook. The same line works whether the sheet was hidden by a user or hidden in code, but it will fail on a sheet whose Visible property was set to xlSheetVeryHidden unless you handle that state too.

What You'll Need

  • Excel on Windows or Mac with macros enabled. The VBA editor is built in; no add-in is required.
  • The workbook open, and the workbook itself not protected with a password you do not have. A protected workbook structure blocks any visibility change.
  • Macro security set to allow macros, or the file saved as .xlsm and trusted. If macros are disabled, the code will not run at all.
  • The exact tab name, or better, the sheet's code name. You can read the code name in the VBA editor's Properties window (press F4 with the sheet selected in the Project Explorer).

Step-by-Step

  1. Open the VBA editor. Press Alt+F11 on Windows, or Fn+Option+F11 on a Mac keyboard where the function keys are remapped. You can also use the Developer tab, then Visual Basic. If the Developer tab is not showing, right-click the ribbon and choose Customize the Ribbon, then tick Developer in the right-hand list.
  2. Find the workbook in the Project Explorer. It appears as VBAProject followed by the file name. If the panel is closed, open it from View > Project Explorer. Expand the workbook node and you will see its sheets listed by code name, plus ThisWorkbook and any modules.
  3. Insert a normal module. With the workbook selected, use Insert > Module. Do not paste the code into a sheet module or into ThisWorkbook unless you specifically want it to run on an event; a standard module keeps things simple and lets you run the macro by name.
  4. Write the unhide procedure. Type something like this into the module:
    Sub UnhideSheet()
        Worksheets("HiddenTab").Visible = xlSheetVisible
    End Sub
    Replace HiddenTab with your tab name. If the name contains spaces or punctuation, keep the quotes around it. If you prefer the code name, write Sheet3.Visible = xlSheetVisible with no quotes, using the code name shown in the Project Explorer.
  5. Run it. Click anywhere inside the procedure and press F5, or use Run > Run Sub/UserForm. You can also place the cursor in the Immediate window (View > Immediate Window, or Ctrl+G) and type the single line Worksheets("HiddenTab").Visible = xlSheetVisible followed by Enter. The Immediate window is the fastest option for a one-off fix because nothing is saved to the file.
  6. Confirm the result. Switch back to Excel with Alt+F11 or the taskbar. The tab should be visible and selectable. If you ran the Immediate window line, the change is not saved until you save the workbook.
  7. Handle very hidden sheets. If the line throws an error or the tab still does not appear, the sheet may be very hidden. Run Worksheets("HiddenTab").Visible = xlSheetVisible from the Immediate window and check the error message; if the property is locked, the workbook structure is protected. Unprotect it first via Review > Protect Workbook (you need the password), then run the line again.
  8. Unhide every hidden sheet at once. Loop through the collection:
    Sub UnhideAll()
        Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            ws.Visible = xlSheetVisible
        Next ws
    End Sub
    This also restores very hidden sheets, because setting the property to xlSheetVisible overrides any hidden state. Note that at least one sheet must stay visible in a workbook, so this loop is safe as written.
  9. Save the workbook as a macro-enabled file if you want to keep the code. Use File > Save As and pick Excel Macro-Enabled Workbook (.xlsm). A plain .xlsx file discards the module on save.

Common Mistakes

  • Using the wrong name. Worksheets("Sheet1") refers to the tab name, not the code name. If the tab was renamed, the call fails with a subscript out of range error. Use the code name to avoid this.
  • Confusing hidden with very hidden. The right-click Unhide command in Excel ignores very hidden sheets, so people assume the sheet is gone. VBA is the only way to bring it back, and the same one-line assignment handles both states.
  • Pasting into the wrong module. Code in a sheet module runs only on that sheet's events. A procedure in ThisWorkbook runs on workbook events. Put general utilities in a standard module.
  • Forgetting workbook protection. If structure is protected, the assignment raises an error. Unprotect first, then re-protect afterwards if you need the protection.
  • Saving as .xlsx. The macro vanishes silently on save. Excel usually warns you, but it is easy to click through.
  • Assuming the change is saved. Anything run from the Immediate window lives only in the open session until you save the file.

Tips

  • Use the code name in production code. It survives tab renames, which is exactly when hard-coded strings break.
  • Wrap the assignment in a small error handler so a missing sheet does not stop a larger routine: check Err.Number after the call and report the sheet name.
  • Keep a helper that lists every sheet and its visibility state, which makes debugging faster than clicking through tabs.
  • If you only need to peek at a sheet, the Immediate window line is the least invasive option because it changes nothing in the saved file.
  • Document which sheets are meant to be very hidden. A future editor who does not know will think the workbook is broken.

Troubleshooting

If nothing happens when you press F5, the cursor is probably outside a procedure. Click inside the Sub and End Sub lines and try again. If you get a compile error, check for a missing quote or a stray character copied from a web page; retype the line rather than pasting.

If you get runtime error 9, subscript out of range, the sheet name does not match any tab in the active workbook. Confirm the workbook you think is active really is: the Immediate window runs against the active workbook, and a second open file can steal focus. Qualify the reference with ThisWorkbook or Workbooks("FileName.xlsx") to be certain.

If you get runtime error 1004, the workbook structure is protected, or the sheet is very hidden and the property is locked. Unprotect the workbook, run the line again, and re-protect afterwards. If the password is unknown, the change cannot be made; there is no supported bypass.

If the tab appears but is greyed out or unselectable, check whether the workbook is shared or the sheet is part of a protected structure. Also confirm the sheet is not set to xlSheetHidden while another setting blocks selection.

If the code runs on one machine but not another, macro security is the usual cause. Check Trust Center settings and whether the file sits in a trusted location.

Frequently Asked Questions

Can I unhide a sheet without VBA?

Yes, for ordinary hidden sheets: right-click any visible tab and choose Unhide, then pick the sheet. That menu does not list very hidden sheets, so VBA is required for those.

What is the difference between hidden and very hidden?

Hidden sheets can be restored from the Excel interface. Very hidden sheets (property xlSheetVeryHidden) do not appear in the Unhide dialog and can only be restored with VBA or by changing the file's structure.

Does the code work on Excel for Mac?

Yes. The VBA editor and the Visible property behave the same. The keyboard shortcut for the editor differs on some Mac keyboards, so use the Developer tab if Fn+Option+F11 does not respond.

Why does my macro say the sheet name is invalid?

The name in quotes must match the tab exactly, including spaces. Switch to the code name shown in the Project Explorer to avoid the problem entirely.

Will unhiding a sheet change formulas or data?

No. Visibility is a display property only. Formulas, values and links are untouched by the change.

Can I unhide all sheets at once?

Yes, with the loop shown above. Excel requires at least one visible sheet, so the loop is safe because it makes every sheet visible rather than hiding them.