Excel cannot automatically hide a column with a worksheet formula or conditional formatting rule. To hide one, select it and use Home > Format > Hide & Unhide > Hide Columns; to make hiding depend on a cell’s value, use a VBA macro, or choose a different approach such as filtering rows or grouping columns.
What “hide a column if” means in Excel
The phrase usually describes a rule such as “hide column C if A1 is blank,” “hide the forecast column if the status says Actual,” or “show optional fields only when needed.” Excel has a built-in command to hide columns, but it does not have a standard worksheet setting that applies a visibility rule to a whole column when a cell changes.
This distinction matters because several Excel features can look similar while doing different things. Conditional formatting changes how cells look; filters hide rows that do not meet criteria; and outline grouping lets a user collapse and expand selected columns. None of those features, by itself, automatically hides an entire column because a particular cell has a value.
Hiding is also different from deleting. A hidden column remains in the workbook, and formulas can still refer to its cells. Hiding is useful for reducing visual clutter, but it is not a way to protect confidential data: someone with access to the workbook may be able to unhide the column or inspect its contents.
Hide or unhide a column manually
For a one-time change, manual hiding is usually the simplest and safest method. Select any cell in the column, or select the column heading, then choose Home > Format > Hide & Unhide > Hide Columns. To restore it, select the column headings on either side of the hidden column and choose Home > Format > Hide & Unhide > Unhide Columns.
- To hide one column, click its letter at the top of the worksheet. To hide several adjacent columns, drag across their headings. For nonadjacent columns, hold Ctrl on Windows while selecting their headings.
- Choose Home > Format > Hide & Unhide > Hide Columns.
- To unhide a column between visible columns, select the headings on both sides of it, then choose Home > Format > Hide & Unhide > Unhide Columns. If the first column is hidden, select the worksheet using the triangle above row 1 and left of column A, then use Unhide Columns.
On Windows, Ctrl+0 hides the selected column or columns. On Mac, Command+0 is the corresponding shortcut in Excel. Shortcut behavior can depend on the keyboard and system settings, so the ribbon command is a dependable alternative. In Excel for the web, use the Home tab’s Format and hide/unhide commands; VBA automation is not available there.
Why a formula or conditional formatting rule cannot do it
Worksheet formulas return values in cells. They do not change structural properties such as a column’s Hidden setting. For instance, an IF formula can display an empty string when a condition is met, but the column itself remains visible. A formula that returns an empty string is not the same as hiding the column.
Conditional formatting has a similar limit. It can change a cell’s fill, font, border, or number format when a condition is true, but it cannot remove the column from the worksheet view. Setting a font color to match the background may make contents harder to see, but it does not hide the column and can make the workbook confusing or inaccessible. It should not be treated as a substitute for hiding.
There is no built-in “hide column if” formula to type into a cell. If a workbook must react automatically to a value, VBA is one option in desktop Excel. If macros are unsuitable, consider whether a filter, outline, or separate report view would meet the need without changing column visibility.
Automatically hide a column with VBA
A worksheet event macro can check a control cell and set a column’s visibility. The example below uses A1 as the control cell and hides column C when A1 is empty or contains only ordinary spaces. Put the code in the worksheet’s code module, not in a regular module.
- In desktop Excel, open the Visual Basic editor from Developer > Visual Basic. If the Developer tab is missing on Windows, enable it through File > Options > Customize Ribbon and select Developer. On Mac, enable the tab in Excel > Settings > Ribbon & Toolbar, then choose Developer > Visual Basic.
- In the editor’s project pane, open the code module for the worksheet where the rule should run. Replace the example cell or column references if your control cell or target column is different.
- Save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Enable macros only for workbooks you trust. Save a separate copy before running or modifying a macro; macro actions cannot be undone with Ctrl+Z.
Private Sub Worksheet_Change(ByVal Target As Range)
' Update when the user edits the control cell.
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
SetColumnVisibility
End Sub
Private Sub Worksheet_Calculate()
' Also update when a formula result on the sheet changes.
SetColumnVisibility
End Sub
Private Sub SetColumnVisibility()
Dim controlValue As Variant
controlValue = Me.Range("A1").Value2
If IsError(controlValue) Then Exit Sub
Me.Columns("C").Hidden = (Len(Trim$(CStr(controlValue))) = 0)
End Sub
When A1 contains text or a number, the example shows column C; when A1 is blank or contains only ordinary spaces, it hides C. The code also checks after worksheet recalculation, so it can respond when A1 contains a formula whose result changes. If A1 contains an error value, the macro leaves the column’s current visibility unchanged.
Because A1 is the control and C is the column being hidden, the user can still reach the control after C disappears. Avoid putting the only control cell inside the column that the macro hides. A workbook with protected sheets, other event macros, or more complex conditions may need adjustments. Excel for the web cannot run VBA, although the workbook can be opened there; use desktop Excel to run or edit this macro.
When filters or grouping are a better fit
If the real goal is to show only records that match a condition, filter rows rather than hide columns. For example, a sales table can be filtered to show only records with Status equal to Open. Select a cell in the table and use Data > Filter, then use the filter menu in the Status heading. This hides nonmatching rows while preserving the table’s columns. It is the right tool when the condition belongs to each record.
If users should choose whether to see a set of related columns, grouping is often clearer than automatic hiding. Select the column headings and choose Data > Outline > Group. Excel adds an outline control that users can use to collapse or expand the grouped columns. Grouping does not inspect a cell or decide for itself when to collapse; it gives users an explicit control.
These approaches solve different problems:
- Hide manually: best for a one-time cleanup or a column that should stay out of sight until someone unhides it.
- Filter: best when the condition determines which rows or records are displayed.
- Group: best when users need a convenient way to collapse and reveal optional columns themselves.
- VBA: best when desktop Excel must automatically change column visibility in response to a control value and macros are acceptable.
Common problems and practical cautions
The column did not unhide: A narrow visible column can be mistaken for a hidden one. Select the headings on both sides of the suspected column and use Unhide Columns. If several columns are hidden, select the whole worksheet first and use the same command.
The macro did not run: Check that the code is in the correct worksheet module, the workbook is saved as .xlsm, and macros are enabled for a trusted file. Worksheet_Change responds to direct edits, while a formula recalculation does not count as a direct edit; that is why the example also includes Worksheet_Calculate.
The column hides but the contents are still accessible: That is expected. Hiding changes the view, not the data’s security. Do not store information in a hidden column on the assumption that other workbook users cannot find it. Use appropriate access controls and avoid including sensitive information in a workbook shared with people who should not see it.
The workbook looks different after a macro runs: A visibility rule can affect printing, formulas, charts, and users who expect a fixed layout. Test the behavior on a copy, document which cell controls the column, and make sure users know how to restore the view. If the macro hides a column containing important controls, labels, or inputs, the workbook can become harder to operate.
Frequently Asked Questions
Can Excel hide a column automatically when a cell is blank?
Not with a normal formula or conditional formatting rule. In desktop Excel, a VBA event macro can hide a column when a control cell is blank. Without macros, hide it manually or use grouping so a user can collapse it.
Can I hide a column when a cell contains a specific word?
Yes, with VBA: change the condition in the macro so it compares the control cell with the required word, and set the target column’s Hidden property accordingly. A formula can test for the word, but the formula alone cannot change column visibility.
Can a filter hide columns instead of rows?
No. Excel’s standard filter hides rows that do not meet selected criteria; it does not automatically hide columns. Use manual hiding, grouping, or VBA if the requirement is about columns.
Will formulas still calculate if a referenced column is hidden?
Yes. Hiding a column does not delete its values or normally prevent formulas from referring to them. The column remains part of the worksheet even though it is not displayed.
Can Excel for the web run a macro to hide a column?
No. Excel for the web does not run VBA macros. You can hide or unhide columns manually in the web app, but use desktop Excel to run VBA automation.
Choosing the right method
For a single column you want out of view, use the Hide Columns command. For data that should appear or disappear based on records, filter rows. For optional sections that people control themselves, group columns. Choose VBA only when the column must change automatically in desktop Excel and the workbook’s macro requirements are acceptable. Keeping the visibility rule simple, documenting its control cell, and testing on a copy makes the resulting workbook easier to maintain.