How to use checkbox to hide/unhide rows or columns in Excel?
In some cases, you may want more dynamic control over your Excel worksheet's display, such as showing or hiding specific rows or columns with a simple interaction. For instance, you could use a checkbox to easily reveal additional details or summaries as needed, or to declutter your worksheet by hiding rarely-used information. A common requirement is to toggle the visibility of certain rows or columns by simply checking or unchecking an ActiveX checkbox. This guide covers detailed steps on how to achieve this using VBA, provides applicable scenarios, explains key code segments, and offers alternative practical solutions for enhanced flexibility in Excel.
Use checkbox to hide/unhide rows or columns with VBA code
Use checkbox to hide/unhide rows or columns with VBA code
Using VBA and an ActiveX Control checkbox allows you to automatically hide or show specific rows or columns, making data management in complex workbooks more straightforward. This solution is ideal when you want real-time control in a worksheet—for example, revealing confidential sections to authorized users or switching between summary and detailed views.
1. Insert an Active X Control checkbox onto your worksheet. To do this, click Developer > Insert > Check Box (ActiveX Control) and draw the checkbox where desired.
Right-click the newly inserted checkbox and select View Code from the context menu. This action opens the VBA editor window directly connected to your checkbox’s event code. See screenshot:
2. In the Microsoft Visual Basic for Applications window that opens, copy and paste the following VBA code into the Code window.
VBA code: Use checkbox to hide/unhide rows or columns
Private Sub CheckBox1_Click()
[C:D].EntireColumn.Hidden = Not CheckBox1
End Sub
Notes and Tips:
- In the VBA code example, [C:D].EntireColumn controls the hiding and unhiding of columns C and D. Change this range to match the rows or columns you wish to toggle. For instance, you can use
[A:A].EntireColumn
for a single column or[6:9].EntireRow
for rows 6 through 9. - To make the code apply to rows instead, modify the relevant part from [C:D].EntireColumn to [6:9].EntireRow. This will hide or display rows6 to9 when you check or uncheck the box.
3. After completing the code, press Alt + Q to exit and return to your worksheet from the Microsoft Visual Basic for Applications editor.
4. Ensure you exit Design Mode by clicking the Design Mode button under the Developer tab. This enables you to interact with the checkbox as a user rather than an editor.
Now, each time you check or uncheck the checkbox, the specified rows or columns will be displayed or hidden automatically. This interactive feature is especially useful for dashboards, flexible reports, or worksheets intended for users with varying information needs.

Unlock Excel Magic with Kutools AI
- Smart Execution: Perform cell operations, analyze data, and create charts—all driven by simple commands.
- Custom Formulas: Generate tailored formulas to streamline your workflows.
- VBA Coding: Write and implement VBA code effortlessly.
- Formula Interpretation: Understand complex formulas with ease.
- Text Translation: Break language barriers within your spreadsheets.
Related articles:
- How to hide/unhide rows or columns with plus or minus sign in Excel?
- How to hide rows based on today’s date in Excel?
- How to hide checkbox when row is hidden in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!