Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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

Supposing you need to use a checkbox to hide or unhide certain rows or columns. For example, when the Active X Control checkbox is checked, the certain rows or columns are displayed, otherwise, they will be hidden. This article shows you the method of how to use checkbox to hide/unhide rows or columns in Excel with details.

Use checkbox to hide/unhide rows or columns with VBA code


You may interest in:

Easily insert or delete multiple check boxes/option buttons in bulk in Excel

With the Kutools for Excel's Batch Insert Check Boxes/Option Buttons or Batch Delete Check Boxes/Option Buttons utilities, you can insert or delete multiple check boxes or option buttons in bulk in your Excel worksheet. See below screenshot:

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 60 days. Read More      Download the free trial now

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

Use checkbox to hide/unhide rows or columns with VBA code


The following VBA code can help you hide/unhide certain rows or columns with checkbox.

1. After inserting an Active X Control checkbox to the worksheet, right click on the checkbox and then select View Code from the right-clicking menu. See screenshot:

2. In the Microsoft Visual Basic for Applications window, 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:

1. In the VBA code, [C:D]. EntireColumn means that the column C and D will be hide or unhide by checking or unchecking the corresponding checkbox.

2. For hiding or displaying certain rows such as row 6:9, please change the [C:D]. EntireColumn to [6:9]. EntireRow in the VBA code.

3. Press the Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.

4. Now please turn off the Design Mode under the Developer tab as below screenshot shown:

From now on, when the checkbox is checked, the specified rows or columns are displayed. When it is unchecked, the specified rows or columns are hidden.


Related articles:


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

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!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    May · 16 days ago
    I was try to unhide the first three role but it was not work.How can I do it ,I know it the person who send me that file wanna know my skill I can solve it or not.
  • To post as a guest, your comment is unpublished.
    Therese · 2 months ago
    Hello,

    Is there a way to hide only one row. If I put 6:9 all rows are hidden, but if I only put 6, it comes out as error. Would appreciate your help, thank you!
    • To post as a guest, your comment is unpublished.
      crystal · 3 days ago
      Hi,
      Please change the second line in the code to:
      [6:6].EntireRow.Hidden = Not CheckBox1.
      Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Lou · 6 months ago
    Hi,

    Hi, I've done the code, it's work good but when I try to make the same in more than one checkbox at the same sheet they work 'together', only hide or unhide the rows if all three checkboxes are selected.
    I am tryint to make these three checkboxes works independent one from another. And let the users mark only one box for at time.
    • To post as a guest, your comment is unpublished.
      crystal · 5 months ago
      Hi Lou,
      Please make sure the checkboxes you created are ActiveX Controls checkboxes. These checkboxes works independently in your worksheet.
      Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Ed · 10 months ago
    Hello,

    I am trying to use this code to hide/unhide on a separate sheet from the checkbox. What do I have to add to make this work? Thanks in advance.

    Private Sub CheckBox1_Click()
    [C:D].EntireColumn.Hidden = Not CheckBox1
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 9 months ago
      Good day,
      As the following code shown, please replace the "Sheet4" with your separate sheet name.

      Private Sub CheckBox1_Click()
      [Sheet4!C:D].EntireColumn.Hidden = Not CheckBox1
      End Sub
  • To post as a guest, your comment is unpublished.
    Cole · 1 years ago
    It seems like this code will only go one direction, i.e. only hide and not unhide them when clicked. Is there a way to correct this?
    • To post as a guest, your comment is unpublished.
      Kent Thegreet · 1 years ago
      We have same problem but find a way to make it work. Please use ActiveX Controls checkbox and not at the Form Control checkbox. The code perfectly works with ActiveX checkbox.


      Private Sub CheckBox1_Click()
      [C:D].EntireColumn.Hidden = Not CheckBox1
      End Sub
    • To post as a guest, your comment is unpublished.
      Kentthegreet · 1 years ago
      We have same problem but I found out we're using Form Controls and not ActiveX Controls. The code perfectly works in ActiveX Control Checkbox button. Just turn off the Design Mode so you can click check the Checkbox.
  • To post as a guest, your comment is unpublished.
    Pieter Ramaut · 2 years ago
    @Wayne:

    Private Sub CheckBox1_Click()
    ActiveSheet.Unprotect Password:="xxxxx"
    Rows("284:351").EntireRow.Hidden = Not CheckBox1
    ActiveSheet.Protect Password:="xxxx"
    End Sub
  • To post as a guest, your comment is unpublished.
    Wayne Bailey · 2 years ago
    Is there a way to use the "Use checkbox to hide/unhide rows or columns with VBA code" on a protected worksheet?