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.
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
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.
- 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!