简体   繁体   English

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

[英]excel macro - checkbox to select other checkboxes

i'm trying to have a selection of optoins via checkboxes. 我正在尝试通过复选框选择视蛋白。 I want to have one specific box automatically check a few other boxes. 我想让一个特定的框自动选中其他几个框。 I'm getting Object required (Error 424) when i click the box in question after assigning the macro below: 当我在分配下面的宏后单击有问题的框时,我得到Object required (Error 424)

any help would be much appreciated 任何帮助将非常感激

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

Does this work for you? 这对您有用吗?

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

i figured out how to do it with editing the cells, not the check boxes 我想出了如何编辑单元格而不是复选框的方法

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 结束子

you can collapse your routine down to: 您可以将常规压缩为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM