Skip to main content

How to use checkbox to hide or unhide worksheet in Excel?

Checkbox is a useful feature in Excel. Here I will show you how to use a checkbox to hide or unhide a specified worksheet in Excel.

Use checkbox to hide or unhide worksheet in Excel


Use checkbox to hide or unhide worksheet in Excel

Supposing you have a checkbox named checkbox1 in your workbook. When unchecking this checkbox, you want a certain worksheet to be hidden automatically in this workbook, and unhide this worksheet while checking the checkbox. Please achieve it as follows.

1. Open the worksheet contains the Checkbox1, right click the sheet tab, and then click View Code from the right-clicking menu.

Note: The check box should be ActiveX check box when you inserting.

2. In the Microsoft Visual Basic for Applications window, please copy and paste the below VBA code into the Code window. See screenshot:

VBA code: Use checkbox to hide or unhide specified worksheet

Private Sub CheckBox1_Click()
    On Error Resume Next
    ThisWorkbook.Sheets("Sheet5").Visible = CheckBox1.Value
End Sub

Note: In the code, Sheet5 is the name of the worksheet you will hide or unhide with checkbox1. Please replace the worksheet name as you need.

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

From now on, when unchecking the checkbox1, the specified worksheet “Sheet5” will be hidden automatically. And you can show it by checking the checkbox. See screenshot:


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

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

Description


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!
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Bonjour,
Je cherche à afficher des pages avec des cases à cocher. Les Chekbox sont toutes sur la même feuille de calcul.
J'ai copié le premier code et l'ai dupliquer.

Private Sub CheckBox1_Click()
On Error Resume Next
ThisWorkbook.Sheets("Eplucher, laver, désinfecter").Visible = CheckBox1.Value
End Sub

Private Sub CheckBox2_Click()
On Error Resume Next
ThisWorkbook.Sheets("Tailler fruits et légumes").Visible = CheckBox1.Value
End Sub

Malheureusement, si je ne coche pas la première case ma seconde case ne fonctionne pas. Pourriez-vous m'aider svp
This comment was minimized by the moderator on the site
Hi Sky53,
I seems that you did not change CheckBox1.Value to the corresponding checkbox name in the second VBA code.
Please change the following line in the second code:
ThisWorkbook.Sheets("Tailler fruits et légumes").Visible = CheckBox1.Value
to
ThisWorkbook.Sheets("Tailler fruits et légumes").Visible = CheckBox2.Value
This comment was minimized by the moderator on the site
Hi Crystal,
Is there a function that would reverse this; ie. sheet is hidden unless checkbox is ticked?
This comment was minimized by the moderator on the site
Hi. I'm very new to ActiveX Controls. I am trying to have multiple checkboxes on one sheet that will hide specific sheets and not all of them or the same one every time. These two scenarios have been my experience. What I need to accomplish is:
CheckBox1 hides Sheet2
CheckBox2 hides Sheet3
CheckBox3 hides Sheet4
CheckBox4 hides Sheet5
CheckBox5 hides Sheet6
CheckBox6 hides Sheet7
CheckBox7 hides Sheet8
CheckBox8 hides Sheet9
This comment was minimized by the moderator on the site
Hi Jack,
Just repeat the code and change the checkbox numbers and the sheet names. Try the below code.

Private Sub CheckBox1_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet2").Visible = CheckBox1.Value

End Sub

Private Sub CheckBox2_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet3").Visible = CheckBox2.Value

End Sub

Private Sub CheckBox3_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet4").Visible = CheckBox3.Value

End Sub

Private Sub CheckBox4_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet5").Visible = CheckBox4.Value

End Sub

Private Sub CheckBox5_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet6").Visible = CheckBox5.Value

End Sub

Private Sub CheckBox6_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet7").Visible = CheckBox6.Value

End Sub

Private Sub CheckBox7_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet8").Visible = CheckBox7.Value

End Sub

Private Sub CheckBox8_Click()

On Error Resume Next

ThisWorkbook.Sheets("Sheet9").Visible = CheckBox8.Value

End Sub
This comment was minimized by the moderator on the site
Crystal,
Thanks so much...it worked perfectly!
This comment was minimized by the moderator on the site
How do I hide or unhide a sheet with multiple checkbox? For example sheet "MainMenu" need to be hide unless checkbox_1, checkbox_2 & checkbox_3 are checked.
This comment was minimized by the moderator on the site
Funciona perfectamente pero, ¿cómo se pueden ocultar varias hojas con el mismo checkbox? Muchas gracias!
This comment was minimized by the moderator on the site
Basta con copiar la linea tantas veces como se quiera nombrando la hoja que debe ser ocultada.

Private Sub CheckBox1_Click()
On Error Resume Next
ThisWorkbook.Sheets("DB2018").Visible = CheckBox1.Value
ThisWorkbook.Sheets("V2018").Visible = CheckBox1.Value
ThisWorkbook.Sheets("R2018").Visible = CheckBox1.Value
End Sub
This comment was minimized by the moderator on the site
How do you do multiple on the same page? How do i then hide sheet 3 or 4 with a checkbox?
This comment was minimized by the moderator on the site
Private Sub CheckBox1_Click()
On Error Resume Next
ThisWorkbook.Sheets("DB2018").Visible = CheckBox1.Value
ThisWorkbook.Sheets("V2018").Visible = CheckBox1.Value
ThisWorkbook.Sheets("R2018").Visible = CheckBox1.Value
End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations