我想通过使用4个多选复选框为单元格赋值,如果条件为真,则每个框的值为1。我想在链接的单元格中总结它们的值,以便单元格值可以变化。例如:
所有这些都是假的,链接的单元格中的值为0
If CheckBox1.Value = True Then Range("D2").Value = 1
If CheckBox1.Value = False Then Range("D2").Value = 0 etc.
我希望通过使用vba宏来解决这个问题。
答案 0 :(得分:0)
用于VBA解决方案
Private Sub CheckBox1_Click()
Dim str As Integer
str = 0
If CheckBox1.Value = True Then str = str + 1
If CheckBox2.Value = True Then str = str + 1
If CheckBox3.Value = True Then str = str + 1
If CheckBox4.Value = True Then str = str + 1
Range("D2").Value = str
End Sub
答案 1 :(得分:0)
在点击之前,只需设置宏foreach复选框。
Public count As Integer
Public Sub btn_Click()
Dim cbName As String
If (count = Null) Then
count = 0
End If
cbName = Application.Caller
If (Sheets("Tabelle1").Shapes(cbName).ControlFormat.Value = xlOn And count < 4) Then
count = count + 1
ElseIf (count > 0) Then
count = count - 1
End If
Range("A1").Value = count
End Sub
答案 2 :(得分:0)
这是我的问题的答案:
选项明确
Sub CheckBox1_Click()
Dim count As Integer
If (count = Null) Then
count = 0
End If
count = 0
If ActiveSheet.Shapes("Check Box 1").ControlFormat = xlOn Then count = count + 1
If ActiveSheet.Shapes("Check Box 2").ControlFormat = xlOn Then count = count + 1
If ActiveSheet.Shapes("Check Box 3").ControlFormat = xlOn Then count = count + 1
If ActiveSheet.Shapes("Check Box 4").ControlFormat = xlOn Then count = count + 1
Range("A1").Value = count
End Sub