Excel VBA Unhide All Columns and Rows: Quick Guide
In this article
Unhiding all columns and rows in an Excel worksheet using VBA is a straightforward process that restores visibility to any hidden data with a single command. This technique is essential for users who need to quickly reveal entire datasets without manually selecting ranges or navigating through the interface menus. By running a simple macro, you can ensure that every column from A to XFD and every row from 1 to 1048576 are visible, effectively resetting the view state of your active sheet.
What You'll Need
- Microsoft Excel installed on your computer (Windows or Mac).
- A workbook containing hidden columns or rows that you wish to reveal.
- Basic familiarity with opening the Visual Basic Editor (VBE) via Alt + F11.
- Macro security settings configured to allow macros to run, or knowledge of how to enable them temporarily.
Step-by-Step
- Open the Visual Basic Editor: Press
Alt + F11on your keyboard to open the Microsoft Visual Basic for Applications window. If this shortcut does not work, navigate to the Developer tab in the Excel ribbon and click "Visual Basic." Note that if the Developer tab is not visible, you may need to enable it via File > Options > Customize Ribbon. - Insert a New Module: In the Project Explorer pane within the VBE, right-click on the name of your current workbook project. Select "Insert" from the context menu, then choose "Module." This creates a blank code window where you can write your script.
- Write the VBA Code: Type the following subroutine into the module window. This code targets the ActiveSheet, ensuring it only affects the currently selected tab.
Sub UnhideAllColumnsAndRows() With ActiveSheet .Cells.EntireColumn.Hidden = False .Cells.EntireRow.Hidden = False End With End Sub - Run the Macro: Click inside the subroutine code. Press
F5to run the macro immediately, or go to the Run menu and select "Run Sub/UserForm." Alternatively, close the VBE, return to Excel, pressAlt + F8, select "UnhideAllColumnsAndRows," and click "Run." - Verify the Results: Check your worksheet to confirm that all previously hidden columns and rows are now visible. The scroll bars should reflect the full extent of the data, and no gaps should remain in the grid.
Common Mistakes
One frequent error is attempting to unhide cells within a specific range rather than the entire sheet. Using Range("A1:Z100").EntireColumn.Hidden = False will only affect those specific columns, leaving others hidden. Always use ActiveSheet.Cells or UsedRange combined with EntireColumn and EntireRow properties to ensure comprehensive coverage. Another common issue is forgetting to save the workbook as a macro-enabled file (.xlsm). If you save as a standard .xlsx file, the VBA code will be stripped out upon closing, meaning you cannot reuse the macro later.
Tips
To make this process even faster, consider assigning the macro to a button or a keyboard shortcut. After creating the macro, go to View > Macros > View Macros, select your macro, and click "Options." Here, you can assign a shortcut key like Ctrl + Shift + U. For users working with multiple sheets, you can modify the code to loop through all worksheets in the workbook by adding a For Each ws In Worksheets loop. Additionally, if you are dealing with filtered data, note that unhiding rows does not remove filters; you may need to add ActiveSheet.ShowAllData if you want to clear filter criteria simultaneously.
Troubleshooting
If the macro runs but nothing changes, check if the sheet is protected. Protected sheets prevent structural changes, including unhiding rows and columns. To fix this, go to Review > Unprotect Sheet before running the macro. If you receive a runtime error, verify that there is at least one active worksheet. If no sheet is active, ActiveSheet returns nothing, causing an error. Ensure you have clicked on a sheet tab in Excel before executing the code. In rare cases, if the workbook contains external links or complex dependencies, Excel might delay the update. Try pressing F9 to force a recalculation after running the macro.
Frequently Asked Questions
Does this unhide grouped rows and columns?
No, this code specifically sets the Hidden property to False. It does not expand collapsed groups created by the Group feature. To ungroup and expand, you would need additional commands such as ActiveSheet.Outline.ShowLevels RowLevels:=8, ColumnLevels:=8.
Can I use this on a Mac?
Yes, the VBA syntax for unhiding columns and rows is identical on Windows and macOS versions of Excel. However, accessing the VBE on a Mac typically requires going to Tools > Macros > Visual Basic Editor instead of using the Alt + F11 shortcut, which may conflict with system shortcuts.
Will this slow down my workbook?
Running this macro once has negligible impact on performance. However, if you trigger it repeatedly on very large datasets with millions of rows, it may cause a brief lag while Excel updates the display. It is generally safe for standard-sized workbooks.
How do I hide all columns again using VBA?
You can reverse the action by changing False to True in the code. For example, .Cells.EntireColumn.Hidden = True will hide all columns. Be cautious when doing this, as it makes navigation difficult until you run the unhide script again.