Checking if a worksheet-based checkbox is checked

Viewed 112999

I'm trying to use an IF-clause to determine whether my checkbox, named "Check Box 1", is checked.

My current code:

Sub Button167_Click()
 If ActiveSheet.Shapes("Check Box 1") = True Then
 Range("Y12").Value = 1
 Else
 Range("Y12").Value = 0
 End If
End Sub

This doesn't work. The debugger is telling me there is a problem with the

ActiveSheet.Shapes("Check Box 1")

However, I know this code works (even though it serves a different purpose):

ActiveSheet.Shapes("Check Box 1").Select
With Selection
.Value = xlOn

My checkboxes (there are 200 on my page), are located in sheet1, by the name of "Demande". Each Checkbox is has the same formatted name of "Check Box ...".

5 Answers

It seems that in VBA macro code for an ActiveX checkbox control, you use

If (ActiveSheet.OLEObjects("CheckBox1").Object.Value = True)

and for a Form checkbox control, you use

If (ActiveSheet.Shapes("CheckBox1").OLEFormat.Object.Value = 1)

Related