跳到主要內容

如何在Excel中一次取消選中或取消選中所有復選框?

如屏幕截圖所示,如何在工作表中一次取消選中或取消選中所有選中的複選框? 在本文中,我將討論一些解決該問題的快速代碼。

doc取消選中復選框1

取消選中或取消選中所有帶有VBA代碼的複選框


箭頭藍色右氣泡 取消選中或取消選中所有帶有VBA代碼的複選框

取消選中或取消選中所有選中的複選框(窗體控件):

如果您的複選框是表單控件,則可以使用以下VBA代碼立即取消選中它們:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊 窗口。

VBA代碼:取消選中或取消選中所有選中的複選框(窗體控件):

Sub ClearCheckBoxes()
'Updateby Extendoffice
    Dim chkBox As Excel.CheckBox
    Application.ScreenUpdating = False
    For Each chkBox In ActiveSheet.CheckBoxes
            chkBox.Value = xlOff
    Next chkBox
    Application.ScreenUpdating = True
End Sub

3。 然後按 F5 鍵以運行此代碼,並且活動工作表中的所有選中的複選框都已被立即取消選中。


取消選中或取消選中所有選中的複選框(ActiveX控件):

如果復選框是ActiveX控件,請應用以下VBA代碼:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊 窗口。

VBA代碼:取消選中或取消選中所有選中的複選框(ActiveX控件):

Sub clearcheckbox()
'Updateby Extendoffcie
    Dim c As Object
    For Each c In ActiveSheet.OLEObjects
        If InStr(1, c.Name, "CheckBox") > 0 Then
            c.Object.Value = False
        End If
    Next
End Sub

3。 然後按 F5 鍵以運行此代碼,並且已在活動工作表中立即取消選中所有選中的複選框。


一次在選擇中插入多個複選框

Excel的Kutools's 批量插入複選框 實用程序可幫助您一次快速插入多個複選框。 點擊下載Kutools for Excel!

最佳辦公生產力工具

🤖 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 (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi!!

Thank you very much, all the codes work very well, it has been extremely useful to me, extraordinary work!

Kind regards
This comment was minimized by the moderator on the site
How would I clear all checkboxes on all worksheets?
This comment was minimized by the moderator on the site
How would clear all checkboxes on all worksheets?
This comment was minimized by the moderator on the site
Hello, Ramon

To clear all the checkboxes accross all sheets, please apply the below codes:
Uncheck all checkboxes from all sheets (Form Controls):
Sub Uncheckallcheckboxes()
    Dim sh As Worksheet
    For Each sh In Sheets
        On Error Resume Next
            sh.CheckBoxes.Value = False
        On Error GoTo 0
    Next sh
End Sub


Uncheck all checkboxes from all sheets (ActiveX Controls):
Sub uncheck_all_ActiveX_checkboxes()
    Dim ws As Worksheet
    Dim xbox As OLEObject
    For Each ws In ThisWorkbook.Worksheets
        For Each xbox In ws.OLEObjects
            ws.OLEObjects(xbox.Name).Object.Value = False
        Next
    Next
End Sub


Please have a try, hope this can help you!
This comment was minimized by the moderator on the site
Hallo,
beim öffnen der datei sollten zwei voneinander abhängige CheckBox1 u. CheckBox2 nicht aktiviert sein

Private Sub CheckBox2_Click()
If CheckBox2 = True Then
CheckBox1 = False
End If
End Sub
Private Sub CheckBox1_Click()
If CheckBox1 = True Then
CheckBox2 = False
End If
End Sub

Danke für eure Hilfe
This comment was minimized by the moderator on the site
Hello, Siegfried
If you want to check one and disable another one, please apply the below code:
Note: The checkbox here you should use the ActiveX Control checkbox.
Private Sub CheckBox2_Click()
If CheckBox2 = True Then
CheckBox1.Enabled = False
Else
CheckBox1.Enabled = True
End If
End Sub
Private Sub CheckBox1_Click()
If CheckBox1 = True Then
CheckBox2.Enabled = False
Else
CheckBox2.Enabled = True
End If
End Sub

Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Merci beaucoup d'avoir partagé le code pour décocher des éléments "CheckBox", cela m'a sauvé ! :o)En effet, en codant un formulaire de saisie fait dans une feuille, je cherchais à trouver un moyen de décocher les cases (en guise de réinitialisation du formulaire) et je ne trouvais pas (à part avec la méthode "Select" qui est, comme nous le savons tous, à bannir), tout simplement car :=> la propriété ".CheckBoxes" n'existe pas en propriété d'une "Worksheet" !=> l'Objet "CheckBoxes" ne figure pas non plus dans l'explorateur d'objets !C'est lunaire cette histoire...Alors merci énormément.Bien à vous.
This comment was minimized by the moderator on the site
Bonjour Lindas,
Je vous en prie. Heureux que cela aide. Pour toute question, n'hésitez pas à nous contacter. Passe une bonne journée.
Sincèrement,
Mandy
This comment was minimized by the moderator on the site
OMG THANK YOU, THIS WEBSITE IS A LIFE SAVER :)
This comment was minimized by the moderator on the site
Big help! thank you!
This comment was minimized by the moderator on the site
How do i uncheck only the boxes in a specific cell range in the active sheet? I have 3 lists in one sheet (Daily/Weekly/Monthly tasks) and wanted to make a "Clear All" button for each list.
This comment was minimized by the moderator on the site
What if I wanted to use a button to activate the macro to clear the boxes?
This comment was minimized by the moderator on the site
Hi, Ariel,
To use a button to activate the macro, first, you should insert a button from the Shapes drop down list, and then right click the button, choose Assign Macro from the context menu, and then select the macro name in the Assign Macro dialog box. Then click OK, and the macro code will be linked to the button.
Please try, hope it can help you!
This comment was minimized by the moderator on the site
many thanks for this vba code, helped greatly.

FYI for people not getting it to work by hitting F5, simply :

developer tab > macros > select the module just created and click options > type a character for the shortcut, such as ctrl+j or ctrl+k.
This comment was minimized by the moderator on the site
Thanks for your help with this. It is much appreciated. However please note: THE SPELLING IS WRONG IN THE CODE FOR STEP #2. VBA code: Uncheck or deselect all checked checkboxes (ActiveX Controls):
Sub clearcheckbox()
'Updateby Extendoffcie
Dim c As Object
For Each c In ActiveSheet.OLEObjects
If InStr(1, c.Name, "CheckBox") > 0 Then
c.Object.Value = False
End If
Next
End Sub

PLEASE NOTE THE WORD "Extendoffcie" IS NOT SPELLED CORRECTLY. SHOULDN'T IT BE "Extendoffice"?? Anyway, just wanted to put that out there
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations