跳到主要內容

如何使用複選框在Excel中隱藏或取消隱藏工作表?

複選框是Excel中的一項有用功能。 在這裡,我將向您展示如何使用複選框在Excel中隱藏或取消隱藏指定的工作表。

使用複選框在Excel中隱藏或取消隱藏工作表


使用複選框在Excel中隱藏或取消隱藏工作表

假設您在工作簿中有一個名為checkbox1的複選框。 取消選中此復選框時,您希望某個工作表自動隱藏在此工作簿中,並在選中該複選框時取消隱藏此工作表。 請如下實現。

1.打開包含Checkbox1的工作表,右鍵單擊工作表選項卡,然後單擊“確定”。 查看代碼 從右鍵單擊菜單中。

備註:插入時,該複選框應為ActiveX複選框。

2。 在裡面 Microsoft Visual Basic for Applications 窗口,請將以下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 for Applications 窗口。

從現在開始,取消選中checkbox1時,指定的工作表“ Sheet5”將自動隱藏。 您可以通過選中復選框來顯示它。 看截圖:


相關文章:

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為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