To unhide columns in Excel using VBA, you explicitly set the column width to a visible value, typically by resetting the Hidden property to False. This is essential when macros or manual actions have hidden columns, making data inaccessible. No special tools are required beyond Excel with VBA enabled, and you must have edit permissions on the workbook.
What You'll Need
- Microsoft Excel (2010 or later) with VBA enabled
- Access to the VBA editor (press Alt+F11)
- A workbook containing hidden columns you need to unhide
- Basic understanding of Excel column references (e.g., A, B, AA, or numbers like 1, 2, 27)
Step-by-Step
- Open the Excel workbook containing the hidden columns you want to unhide.
- Press Alt+F11 to open the Visual Basic for Applications (VBA) editor.
- In the Project Explorer panel on the left, locate the workbook you are working with (e.g., VBAProject (YourWorkbookName.xlsm)). If the Project Explorer is not visible, press Ctrl+R to display it.
- Right-click the workbook name and select Insert > Module. This creates a new blank code module.
- In the new module window, type or paste the following line of code:
Columns("A:C").Hidden = False. Replace "A:C" with the actual column range you need to unhide (e.g., "D:D" for a single column, "Z:AA" for multiple columns). - Press F5 or click the Run button (green triangle) in the toolbar to execute the code. Do not close the VBA editor yet.
- Switch back to Excel by clicking its window or pressing Alt+Tab. The specified columns should now be visible.
- To make this code reusable, save the workbook as a macro-enabled file (.xlsm) by going to File > Save As and selecting "Excel Macro-Enabled Workbook (*.xlsm)" from the file type dropdown.
Common Mistakes
- Using incorrect column references: Typing "1:3" instead of "A:C" will cause an error. VBA expects letter-based column identifiers, not row numbers.
- Forgetting to use quotes around column ranges:
Columns(A:C).Hidden = Falsewithout quotes will throw a compile error because VBA interprets A:C as undefined variables. - Running the code on a protected worksheet: If the sheet is protected, the macro will fail silently. You must unprotect the sheet first using
ActiveSheet.Unprotectbefore un hiding columns, or include password logic if one was used. - Assuming all hidden columns are contiguous: If columns are hidden non-sequentially (e.g., B, D, F), using
Columns("B:F").Hidden = Falsewill unhide B, C, D, E, F — including columns that were never hidden. To target only hidden ones, loop through each column individually. - Using
Columns(2).Hidden = Falsefor column B: This works, but many users confuse column index (number) with letter reference. Both are valid, but mixing them without understanding can cause confusion.
Tips
- To unhide all columns in a worksheet at once, use:
Cells.Columns.Hidden = False. This resets the entire sheet’s column visibility. - Use a loop to unhide only columns that are currently hidden:
For Each col In Range("A1:Z100").Columns: If col.Hidden Then col.Hidden = False: Next col. This avoids accidentally revealing columns you meant to keep hidden. - Assign a shortcut key to your macro: After saving the macro, go to View > Macros > View Macros, select your macro, click Options, and assign a letter (e.g., U) to Ctrl+Shift+U for one-click unhide.
- Test your macro on a copy of your workbook first. Hidden columns may contain sensitive data or formatting that could be disrupted if the code targets too broad a range.
- If you frequently unhide the same columns, store the range as a named range (Formulas > Define Name) and reference it in VBA as
Range("MyColRange").Columns.Hidden = False.
Troubleshooting
- If the columns do not unhide after running the code, check whether the worksheet is protected. Go to Review > Unprotect Sheet. If a password was used, you must enter it. If you don’t know the password, the macro cannot bypass it.
- If Excel crashes or freezes during macro execution, close and reopen the file. Then, try running the code on a smaller range (e.g., one column at a time) to isolate the issue.
- If you see a "Compile error: Invalid qualifier" message, verify that you typed
Columns("A:C")with quotes. Remove any accidental spaces or typos. - If the macro runs without error but columns stay hidden, ensure the code is targeting the correct worksheet. Use
Worksheets("Sheet1").Columns("A:C").Hidden = Falseto specify the sheet name explicitly. - If you’re using Excel Online or Excel for the web, VBA macros are not supported. You must use the desktop version of Excel to run this code.
Frequently Asked Questions
Can I unhide columns without VBA using Excel’s interface?
Yes. Select the columns adjacent to the hidden ones (e.g., select columns A and D if column B and C are hidden), right-click, and choose Unhide. This method works for simple cases but is less efficient for complex or repeated tasks.Why can’t I see the columns even after running the VBA code?
The columns might be set to a width of zero. After un hiding them, manually drag the column edge to restore width, or addColumns("A:C").ColumnWidth = 8.43 to your code to reset width.
Does un hiding columns with VBA affect formulas or data?
No. Unhiding columns only changes visibility. Formulas, formatting, and data remain intact. However, if a formula references a cell in a previously hidden column, it will now recalculate and display correctly.Can I unhide columns across multiple sheets at once?
Yes. Use a loop:For Each ws In ThisWorkbook.Worksheets: ws.Columns("A:C").Hidden = False: Next ws. This applies the change to every sheet in the workbook.
What if I accidentally hide the wrong columns?
You can undo the action immediately with Ctrl+Z if you haven’t closed the workbook. If the workbook was saved after the change, you’ll need to re-run the macro with corrected column references or restore from a backup.Is there a limit to how many columns I can unhide with one VBA command?
No. Excel supports up to 16,384 columns (XFD). VBA can unhide all of them with a single command likeCells.Columns.Hidden = False, though performance may slow slightly on very large ranges.