Chuck
03-24-2008, 07:46 AM
Hi all, I am a newbie to Excel VB coding, any help would be greatly appreciated. I am trying to create some code that will uncheck a previously checked CheckBox. I have a worksheet with 8 CheckBoxes broken into two series (1-4) and (5-8). I am trying to get my code to work so that when CheckBox 1 is checked, any other checked CheckBox (2,3, or 4) becomes unchecked, likewise, if Checkbox 2 is checked, 1,3 and 4 become unchecked. The second series, 5-8, would be indentical to the previous one.
Here is the code I have been playing around with:
Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
Range("treat1") = "1"
Range("treat2") = "0"
Range("treat3") = "0"
Range("treat4") = "0"
End If
End Sub
Sub CheckBox2_Click()
If CheckBox2.Value = True Then
CheckBox1.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
Range("treat2") = "1"
Range("treat1") = "0"
Range("treat3") = "0"
Range("treat4") = "0"
End If
End Sub
Sub CheckBox3_Click()
If CheckBox3.Value = True Then
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox4.Value = False
Range("treat3") = "1"
Range("treat1") = "0"
Range("treat2") = "0"
Range("treat4") = "0"
End If
End Sub
Sub CheckBox4_Click()
If CheckBox4.Value = True Then
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox1.Value = False
Range("treat4") = "1"
Range("treat2") = "0"
Range("treat3") = "0"
Range("treat1") = "0"
End If
End Sub
I always get the "Run-time error '424': Object required" error.
I am thinking that if I get the first series to work, I can just change the CheckBox numbers to get the rest to work. Any help would be greatly appreciated. Thanks in advance for whoever can help!
-Chuck.
Here is the code I have been playing around with:
Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
Range("treat1") = "1"
Range("treat2") = "0"
Range("treat3") = "0"
Range("treat4") = "0"
End If
End Sub
Sub CheckBox2_Click()
If CheckBox2.Value = True Then
CheckBox1.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
Range("treat2") = "1"
Range("treat1") = "0"
Range("treat3") = "0"
Range("treat4") = "0"
End If
End Sub
Sub CheckBox3_Click()
If CheckBox3.Value = True Then
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox4.Value = False
Range("treat3") = "1"
Range("treat1") = "0"
Range("treat2") = "0"
Range("treat4") = "0"
End If
End Sub
Sub CheckBox4_Click()
If CheckBox4.Value = True Then
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox1.Value = False
Range("treat4") = "1"
Range("treat2") = "0"
Range("treat3") = "0"
Range("treat1") = "0"
End If
End Sub
I always get the "Run-time error '424': Object required" error.
I am thinking that if I get the first series to work, I can just change the CheckBox numbers to get the rest to work. Any help would be greatly appreciated. Thanks in advance for whoever can help!
-Chuck.