跳到主要內容

如何根據Excel中的單元格值選中復選框?

您可能知道如何根據複選框更改單元格值。 但是,您知道如何根據Excel中的單元格值自動選中一個複選框嗎? 本文將向您展示實現它的方法。

使用公式根據單元格值選中復選框
使用VBA代碼根據單元格值選中復選框


使用公式根據單元格值選中復選框

假設您希望當單元格A1中的值等於“測試”時自動選中復選框1。 請執行以下操作。

1.插入複選框(表單控件)後,選擇它並通過輸入以下內容將其鏈接到指定的單元格C2 = C2 進入公式欄。

ActiveX控件 複選框,請右鍵單擊它並選擇 氟化鈉性能 從右鍵單擊菜單中。 而在 氟化鈉性能 對話框中,輸入 連鎖細胞鏈接單元 字段,然後關閉對話框。 看截圖:

2.選擇內襯單元格(C2),然後輸入公式 = IF(A2 =“ Test”,TRUE,FALSE) 進入編輯欄,然後按 Enter 鍵。

備註:在公式中,“ A2”和“測試”是單元格以及您需要根據其自動選中復選框的單元格值。

3.在單元格A1中輸入值“測試”時,將自動選中相應的複選框。 看截圖:

注意:此公式不區分大小寫。


使用VBA代碼根據單元格值選中復選框

您可以運行以下VBA代碼,以基於Excel中的單元格值選中復選框。

1.右鍵單擊 工作表標籤 選中基於單元格值的複選框,然後單擊 查看代碼 從右鍵單擊菜單中。

2。 在裡面 Microsoft Visual Basic for Applications 窗口,請將以下VBA代碼複製並粘貼到“代碼”窗口中。

VBA代碼:根據單元格值選中復選框

Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("A2").Value = "Test" Then
        ActiveSheet.CheckBoxes("Check Box 1").Value = xlOn
    Else
        ActiveSheet.CheckBoxes("Check Box 1").Value = xlOff
    End If
End Sub

備註:在代碼中,A2和Test是單元格以及您需要基於其自動選中復選框的單元格值。 複選框1是複選框的名稱。

3。 按 其他 + Q 鍵以關閉“ Microsoft Visual Basic應用程序”窗口。

在單元格A2中輸入值“測試”時,將自動選中指定的複選框。

備註:此代碼區分大小寫。

小提示: 如果您想將多個複選框批量插入選定的範圍內,可以嘗試使用 批量插入複選框 的效用 Excel的Kutools,或將多個選項按鈕與 批量插入選項按鈕 效用。 此外,您可以一次刪除所有復選框 批量刪除複選框 實用程序,如下圖所示。 你可以去 下載Kutools for Excel! (30 天免費試用).


相關文章:

最佳辦公生產力工具

🤖 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 (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
can i do thisin google sheet?
This comment was minimized by the moderator on the site
Hello,

I downloaded a template from Microsoft Office itself for Excel.
There is a column with a check box and a check mark.
I can activate the check mark by typing "1", when I do this the task will be set in a lighter color.

But I don't get the check box activated. It is with color and not a check mark. I see this in the formula bar =ALS(G7="";"☐";"⬛") (I think ALS is IF. My language is set on Dutch). I've already been searching but no results. There is no format control, int the properties I don't see anything either.
This comment was minimized by the moderator on the site
Queria saber como fazer isto com mais de um parâmetro de comparação. Por exemplo: quero que automaticamente minha célula A1 retorne o valor TRUE se e somente se outras três células B1, C1 e D1 estiverem todas com o valor TRUE (caso pelo menos uma delas esteja com o valor FALSE, a célula A1 continuará com o valor FALSE). Já tentei usar várias fórmulas usando o comando IF, mas sem êxito. Por favor, você sabe me dizer qual a fórmula certa para conseguir isto? :)
This comment was minimized by the moderator on the site
Descobri! Apenas usar:

=if(and(B1=true, C1=true, D1=true), true, false)
This comment was minimized by the moderator on the site
I am trying to use the checkbox to display specific text to another sheet when it is checked or true and remain blank when it is unchecked or false.
This comment was minimized by the moderator on the site
specifically if it is true I would like it to display 0700-0800 and if it is false display a blank cell.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations