excel macro - 复选框以选择其他复选框

时间:2018-02-09 19:42:24

标签: excel vba checkbox

我试图通过复选框选择optoins。我想让一个特定的盒子自动检查其他一些盒子。我在下面分配宏后点击相关方框时收到Public Sub CheckBox1_Click() If CheckBox21.Value = True Then CheckBox2.Value = True CheckBox5.Value = True CheckBox6.Value = True CheckBox18.Value = True CheckBox19.Value = True CheckBox20.Value = True CheckBox22.Value = True CheckBox23.Value = True CheckBox2.Enabled = False CheckBox5.Enabled = False CheckBox6.Enabled = False CheckBox18.Enabled = False CheckBox19.Enabled = False CheckBox20.Enabled = False CheckBox22.Enabled = False CheckBox23.Enabled = False Else CheckBox2.Enabled = True CheckBox5.Enabled = True CheckBox6.Enabled = True CheckBox18.Enabled = True CheckBox19.Enabled = True CheckBox20.Enabled = True CheckBox22.Enabled = True CheckBox23.Enabled = True End If End Sub

任何帮助将不胜感激

{{1}}

3 个答案:

答案 0 :(得分:0)

这对你有用吗?

Private Sub CheckBox21_Change()

If CheckBox21.Value = True Then
    CheckBox2.Value = True
    CheckBox5.Value = True
    CheckBox6.Value = True
    CheckBox18.Value = True
    CheckBox19.Value = True
Else
    CheckBox2.Value = False
    CheckBox5.Value = False
    CheckBox6.Value = False
    CheckBox18.Value = False
    CheckBox19.Value = False
End If

答案 1 :(得分:0)

我想出了如何通过编辑单元格来完成它,而不是复选框

Public Sub CheckBox1_Click()
If Range("AF3").Value = True Then
    Range("AA3").Value = True
    Range("AC3").Value = True
    Range("AE3").Value = True
    Range("AG3").Value = True
    Range("AD3").Value = True
    Range("AI3").Value = True
    Range("AH3").Value = True
    Range("AK3").Value = True
Else
    Range("AA3").Value = False
    Range("AC3").Value = False
    Range("AE3").Value = False
    Range("AG3").Value = False
    Range("AD3").Value = False
    Range("AI3").Value = False
    Range("AH3").Value = False
    Range("AK3").Value = False
End If

End Sub

答案 2 :(得分:0)

你可以将你的常规折叠到:

Public Sub CheckBox1_Click()
    Range("AA3,AC3:AE3,AG3:AI3,AK3").Value = Range("AF3").Value
End Sub