Hide or Unhide Excel Columns with a Check Box and VBA
Question details
Use a Form Control check box and VBA to hide or show columns K and L in an Excel worksheet.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet user wants to control the visibility of columns K and L by checking or clearing a box.
- Observed behavior
- Columns K and L should be hidden when the box is checked and displayed when it is cleared.
Open the workbook in a desktop version of Excel that supports VBA and Form Controls. If the Developer tab is hidden, enable it in Excel's ribbon settings.
Assign a VBA macro to a Form Control check box
Use this method to hide columns K and L when the check box is selected and show them when it is cleared.
On the worksheet, select Developer > Insert, choose Check Box under Form Controls, and draw it on the sheet.
Right-click the check box to select it, then check the Name Box to the left of the formula bar. If necessary, enter Check Box 1 in the Name Box and press Enter.
Right-click the check box, choose Assign Macro, enter HideUnhide, and click New. In the VBA editor, replace the generated procedure with: Sub HideUnhide() With ActiveSheet .Columns("K:L").Hidden = (.Shapes("Check Box 1").ControlFormat.Value = 1) End With End Sub
Return to Excel and use File > Save As to save the workbook as an Excel Macro-Enabled Workbook (.xlsm). If prompted when reopening a trusted workbook, enable macros, then click the check box to hide or show columns K and L.

Manage spreadsheet columns with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with spreadsheets and moving between Office formats. It does not fix Excel's VBA behavior; check box and macro compatibility may vary.

Frequently Asked Questions
How do I show the Developer tab in Excel?
In Excel's ribbon settings, enable the Developer tab. On Windows, go to File > Options > Customize Ribbon, select Developer, and click OK.
Can I hide different columns with the same macro?
Yes. In the VBA editor, change .Columns("K:L") to the column range you want, such as .Columns("B:D"), and save the macro-enabled workbook.
Why does clicking the check box do nothing?
Right-click the check box and choose Assign Macro to confirm that HideUnhide is assigned. Also check that the shape name in the code matches the check box name and that macros are enabled for the trusted workbook.
Can I use this VBA check box in Excel for the web?
Excel for the web cannot run VBA macros. Open the workbook in a supported desktop version of Excel to use the Form Control macro.
Why must I save the workbook as an XLSM file?
The XLSM format preserves VBA macros. Use File > Save As and choose Excel Macro-Enabled Workbook before closing the file.




