To show all hidden rows in an Excel worksheet using VBA, you need to unhide rows by setting their Hidden property to False across the used range or entire sheet. This process requires enabling macros and writing a short VBA macro—no add-ins or third-party tools are needed. Before starting, ensure Developer tab is visible and macros are enabled in Excel’s Trust Center settings.
What You'll Need
- Microsoft Excel (2010 or later)
- Developer tab enabled (to access the VBA editor)
- Macro security set to enable macros (temporarily, if needed)
- A workbook with hidden rows to unhide
Step-by-Step
- Open your workbook in Excel. Save it as a macro-enabled file (.xlsm) if it isn’t already—this ensures VBA code persists. If the file is .xlsx, Excel won’t save VBA code.
- Enable the Developer tab if it’s missing: Go to
File > Options > Customize Ribbon, then check the box next to Developer under Main Tabs. Click OK. - Open the VBA editor by pressing
Alt + F11on Windows (orFn + Option + F11on Mac, though VBA support is limited on Mac). This opens the Visual Basic for Applications window. - Insert a new module: In the VBA editor, go to
Insert > Module. A blank code window appears on the right. - Paste the VBA code below into the module window. This code loops through all rows in the used range of the active sheet and unhides any hidden rows:
Sub ShowAllHiddenRows() Dim ws As Worksheet Dim rng As Range Dim row As Range Set ws = ActiveSheet On Error Resume Next Set rng = ws.UsedRange On Error GoTo 0 If Not rng Is Nothing Then For Each row In rng.Rows row.EntireRow.Hidden = False Next row End If MsgBox "All hidden rows in the active sheet are now visible.", vbInformation End Sub - Run the macro by pressing
F5while the cursor is inside the macro code, or return to Excel and go toDeveloper > Macros, selectShowAllHiddenRows, then click Run. - Verify the result. Scroll through the worksheet—rows that were previously hidden (with a thin line between row numbers) should now be fully visible and editable.
Common Mistakes
- Running the macro on the wrong sheet: The code targets
ActiveSheet. If multiple sheets exist, ensure the correct sheet is selected before running. To fix this, replaceActiveSheetwithSheets("Sheet1")(replace “Sheet1” with your sheet’s name). - Macro security blocking execution: If Excel shows a security warning or the macro won’t run, go to
File > Options > Trust Center > Trust Center Settings > Macro Settingsand select Enable all macros (temporarily). Restart Excel and try again. - Using
Cellsinstead ofUsedRange: An alternative likeRows.Hidden = Falsemay be tempting, but referencingCellsdirectly without a sheet qualifier can cause errors or affect unintended rows.UsedRangeis safer and more efficient. - Forgetting to save as .xlsm: Saving as .xlsx strips VBA code silently. Always verify the file type in the Save As dialog.
Tips
- Unhide specific columns too: To unhide columns alongside rows, add
For Each col In rng.Columns: col.EntireColumn.Hidden = False: Next colinside the same loop. - Add error handling: Wrap the macro in
On Error GoTo ErrorHandlerto catch issues like protected sheets (unprotected first or modify code to unprotect with a password). - Assign a button: On the Developer tab, insert a button (Form Controls), draw it on the sheet, and assign
ShowAllHiddenRowsto it for one-click access. - Test on a copy first: Especially if the sheet has formulas or formatting dependencies, test the macro on a duplicate worksheet to avoid unintended changes.
Troubleshooting
If the macro runs but rows remain hidden, follow these checks:
- Confirm row visibility: Manually check if rows are truly hidden. Right-click a row number above/below a suspected hidden area and select Unhide from the context menu. If Excel shows no hidden rows, the issue may be with row height (set to 0). In that case, add
row.RowHeight = 15afterHidden = Falseto force a standard height. - Check for filtered rows: VBA’s
Hiddenproperty only affects manually hidden rows—not AutoFilter results. To clear filters, runws.AutoFilterMode = Falsebefore unhiding rows. - Sheet protection: If the sheet is protected, the macro fails silently. Unprotect it first via
Review > Unprotect Sheet(no password needed if none was set), or modify the macro to unprotect usingws.Unprotect Password:="yourpassword"(replace placeholder). - Verify macro execution: Add
Debug.Print ws.UsedRange.Rows.Countbefore the loop. PressCtrl + Gin the VBA editor to open the Immediate Window and confirm the count is non-zero. If it’s zero,UsedRangemay be empty or misidentified (e.g., due to stray data far off-screen). - Restart Excel: Occasionally, Excel’s macro engine stalls. Close all workbooks, restart Excel, re-enable macros, and retry.
Frequently Asked Questions
Does this work on protected sheets?
No—unless you unprotect the sheet first or include unprotect code in the macro. Protected sheets block row unhiding by default.
Can I unhide rows across all sheets at once?
Yes. Replace the code’s sheet loop with:
For Each ws In ThisWorkbook.Worksheets
For Each row In ws.UsedRange.Rows
row.EntireRow.Hidden = False
Next row
Next wsEnsure no sheets are protected without passwords in the code.
Will this delete data?
No. Unhiding rows only changes visibility; it does not alter data, formulas, or formatting.
Why does the macro show a runtime error '1004'?
This often occurs if UsedRange is invalid (e.g., sheet has no data) or the sheet is protected. Check for blank cells at the sheet’s edges that extend the used range incorrectly—delete them manually first. Also ensure no merged cells interfere with row references.
Can I use this on Excel Online?
No. Excel Online does not support VBA macros. You must use the desktop version of Excel (Windows or Mac) to run this code.
Is there a non-VBA way to unhide rows?
Yes. Select the rows above and below the hidden area (e.g., rows 5 and 7 if row 6 is hidden), right-click, and choose Unhide. Alternatively, use Home > Format > Hide & Unhide > Unhide Rows. However, VBA is faster for large or scattered hidden sections.