LauraS
LauraS

Reputation: 23

Clear all check boxes

I'm creating a macro to clear cells and ALL CheckBoxes from my form, however it only clears CheckBoxes in the first group box (and leaves all other check boxes ticked). My code:

Sub clearcheck()
 ActiveSheet.CheckBoxes.Value = False

 Range("D4:E4").Select

    Selection.ClearContents
    ActiveSheet.Shapes.Range(Array("Label 61")).Select
    Range("H4:I4").Select
    Selection.ClearContents
    Range("M4:N4").Select
    Selection.ClearContents

 End Sub

Screenshot

 https://i.sstatic.net/ddkxF.png

Can anyone help me with my code?

Upvotes: 2

Views: 885

Answers (1)

Ralph
Ralph

Reputation: 9444

You are probably facing the typical problem of mixing FormControls with ActiveX controls. Try this code and let me know if it works:

Public Sub UncheckAll()

On Error Resume Next
For Each x In Worksheets("Sheet2").Shapes
    Select Case x.Type
    Case 8
        Debug.Print x.Name & " is a FormControl"
        x.OLEFormat.Object.Value = False
    Case 12
        Debug.Print x.Name & " is an ActiveX Control"
        Worksheets("Sheet2").OLEObjects(x.Name).Object.Value = False
    Case Else
        Debug.Print x.Name & " is neither"
    End Select
Next x
On Error GoTo 0

End Sub

Upvotes: 1

Related Questions