When adding a checkbox, how do you access the value from VBA?
For completeness, if you're using an ActiveX checkbox instead of a regular checkbox, the syntax is
If Sheet1.Shapes("chkMyCheck").OLEFormat.Object.Object.Value Then
...
found using the Locals window and a variable set to the shape -
Dim shp as Shape
Set shp = Sheet1.Shapes("chkMyCheck")
Stop
One way:
Dim oCheck As Object
Set oCheck = Sheet1.CheckBoxes("chkMyCheck")
MsgBox (oCheck.Value = xlOn)
Edit: here's another method - maybe this one will work for you...
Sub Tester2()
Dim sh As Shape
For Each sh In Sheet1.Shapes
If sh.Type = msoFormControl Then
If sh.FormControlType = xlCheckBox Then
Debug.Print sh.Name & "=" & sh.ControlFormat.Value
End If
End If
Next sh
End Sub
Figured it out
If Sheet1.Shapes("chkMyCheck").ControlFormat.Value = xlOn Then
.....