我試圖創建類似於「Mastercheckbox」的東西,它會自動檢查我的工作表上的所有其他複選框。所以我試圖啓動下面的VBA代碼,只要我點擊「Mastercheckbox」我使用表單工具而不是Active X創建我的複選框,以確保我的VBA與任何機器兼容(我讀該Active X可能會造成一些問題),並已得到了下面的代碼:在for循環檢查複選框的值,並相應地設置所有其他複選框的值
Sub Mastercheckbox()
Dim Chk As CheckBox
With ActiveSheet.Shapes("Mastercheckbox")
If .ControlFormat.Value = False Or .ControlFormat.Value = True Then
If .ControlFormat.Value = False Then
For Each chk In ActiveSheet.CheckBoxes
If Not chk.Name = "Mastercheckbox" Then
chk.Value = False
End If
Next chk
End If
If Not .ControlFormat.Value = True Then
For Each chk In ActiveSheet.CheckBoxes
If Not chk.Name = "Mastercheckbox" Then
chk.Value = True
End If
Next chk
End If
Else: MsgBox ("couldn't check value of mastercheckbox")
End If
End With
End Sub
一切正常,但檢查Mastercheckbox的只是工作不因某種原因值,並將其直接跳到其他情況。誰能幫我嗎?
謝謝,這工作很好!讓我的一天:) –
不客氣。看看我的編輯,稍微縮短代碼 – user3598756