I have a table with 12 entries, and a checkbox next to each entry. The first row of this list shows "All".
What I am trying to do at the moment is to code the event triggers CheckBox(x)_Click so that when the checkbox next to "All" is checked, everything else is unchecked, and if any other checkbox is checked, the All would be unchecked.
Although it's pretty easy to hard code each and every event, I would like to have 1 set of code which can be just copied and pasted into a new checkbox event, in the case there's a new box added. This would allow easier changes within the list (e.g. decide that the "All" should be at the end of the list rather than the top), and would also make it easier to refer to the corresponding cell as Checkbox(x) refers to Cells(x,1) of the range.
At the moment I have:
What I am asking is this:
If, for example, I'm coding in the event CheckBox1_Click, is there any way for refer to that Checkbox automatically? Something like Checkbox.This, which would refer to Checkbox1. And if it is possible, would I be able extract the "1" out of the name? I'm planning to use
to loop around the rest.
What I am trying to do at the moment is to code the event triggers CheckBox(x)_Click so that when the checkbox next to "All" is checked, everything else is unchecked, and if any other checkbox is checked, the All would be unchecked.
Although it's pretty easy to hard code each and every event, I would like to have 1 set of code which can be just copied and pasted into a new checkbox event, in the case there's a new box added. This would allow easier changes within the list (e.g. decide that the "All" should be at the end of the list rather than the top), and would also make it easier to refer to the corresponding cell as Checkbox(x) refers to Cells(x,1) of the range.
At the moment I have:
Code:
Private Sub CheckBox1_Click()
If Range("TLList").Cells(1, 1) = "All" Then
If CheckBox1.Value = True Then
CheckBox10.Value = False
CheckBox11.Value = False
CheckBox12.Value = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
CheckBox5.Value = False
CheckBox6.Value = False
CheckBox7.Value = False
CheckBox8.Value = False
CheckBox9.Value = False
End If
End If
End Sub
If, for example, I'm coding in the event CheckBox1_Click, is there any way for refer to that Checkbox automatically? Something like Checkbox.This, which would refer to Checkbox1. And if it is possible, would I be able extract the "1" out of the name? I'm planning to use
Code:
ActiveSheet.Shapes("CheckBox" & i)