VBA & Macro Problems

Hide or Unhide Excel Columns with a Check Box and VBA

Camila MilosovichCamila Milosovich Nov 18, 2026 868 views

Question details

Use a Form Control check box and VBA to hide or show columns K and L in an Excel worksheet.

Hide or Unhide Excel Columns with a Check Box and VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Insert the check box

On the worksheet, select Developer > Insert, choose Check Box under Form Controls, and draw it on the sheet.

2
Check its name

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.

3
Create the macro

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

4
Save and test

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.

Assign a VBA macro to a Form Control check box
Match the check box name: The name in Shapes("Check Box 1") must match the Form Control's name. If you use a different name, update the code accordingly.
Free Microsoft Office alternative

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.

Hide or show spreadsheet columns using familiar controls.Open and work with Microsoft Excel formats such as XLSX.Use a lightweight office suite with a familiar interface.Move existing Office documents into WPS Office with minimal disruption.
microsoft office alternative - wps office

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.