Skip to main content

How to use checkbox to hide/unhide rows or columns in Excel?

Author: Siluvia Last Modified: 2025-07-09

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:

a screenshot of opening the code editor

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.

a screenshot of turning off the Design Mode

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.

a screenshot of kutools for excel ai

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.
Enhance your Excel capabilities with AI-powered tools. Download Now and experience efficiency like never before!

Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

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!