跳到主要内容

如何使用复选框在Excel中隐藏或取消隐藏工作表?

复选框是Excel中的一项有用功能。 在这里,我将向您展示如何使用复选框在Excel中隐藏或取消隐藏指定的工作表。

使用复选框在Excel中隐藏或取消隐藏工作表


使用复选框在Excel中隐藏或取消隐藏工作表

假设您在工作簿中有一个名为checkbox1的复选框。 取消选中此复选框时,您希望某个工作表自动隐藏在此工作簿中,并在选中该复选框时取消隐藏此工作表。 请如下实现。

1.打开包含Checkbox1的工作表,右键单击工作表选项卡,然后单击“确定”。 查看代码 从右键单击菜单中。

备注:插入时,该复选框应为ActiveX复选框。

2.在 Microsoft Visual Basic应用程序 窗口,请将以下VBA代码复制并粘贴到“代码”窗口中。 看截图:

VBA代码:使用复选框隐藏或取消隐藏指定的工作表

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

备注:在代码中,Sheet5是您将使用checkbox1隐藏或取消隐藏的工作表的名称。 请根据需要替换工作表名称。

3。 按 其他 + Q 同时关闭按键 Microsoft Visual Basic应用程序 窗口。

从现在开始,取消选中checkbox1时,指定的工作表“ Sheet5”将自动隐藏。 您可以通过选中复选框来显示它。 看截图:


相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
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