Texas Aggie, selections such as that are considered bad coding
practice unless absolutely necessary. Also, that code will always do
the same thing, regardless of if the checkbox is checked or not.
Should use something like this (assuming the checkbox was added from
the Forms toolbar).
Sub CheckBox1_Click()
Dim colorRange As Range, chkBox As Shape
Set colorRange = ActiveSheet.Range("A2:A5")
For Each chkBox In ActiveSheet.Shapes
If chkBox.Name = "Check Box 1" Then
If ActiveSheet.CheckBoxes(chkBox.Name) _
.Value = 1 Then
colorRange.Interior.ColorIndex = 36
Else
colorRange.Interior.ColorIndex = xlNone
End If
Exit For
End If
Next
Set colorRange = Nothing
End Sub
A simpler way:
Sub CheckBox1_Click()
Dim colorRange As Range, chkBoxName As String
chkBoxName = "Check Box 1"
Set colorRange = ActiveSheet.Range("A2:A5")
For Each CheckBox In ActiveSheet.CheckBoxes
If CheckBox.Name = chkBoxName Then
If CheckBox.Value = 1 Then
colorRange.Interior.ColorIndex = 36
Else
colorRange.Interior.ColorIndex = xlNone
End If
Exit For
End If
Next CheckBox
Set colorRange = Nothing
End Sub
Now what exactly is that supposed to mean? I wasn't trying to step on
any toes or ruffle any feathers, but I apparently I did a poor job at
that. We are all on these news groups to learn and to share. Time to
grow up.
Now that's funny. I have been critiqued several times on this
newsgroup since joining a while back. Never took any of it to heart.
I took it as people trying to help me grow and improve my coding. If
you will go back and read my original response, there is nothing
malicious or harmful in anything that I said.
All that being said, I'm done. To the OP, I hope that you got your
question answered.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.