Excel VBA script remove all checkboxes in a column

I am trying to clear all active X checkboxes in a specific cell range or column

It seems to be simple, as I was able to do this for the whole worksheet with the code below. I'm just not sure how to change this to apply to only one column or range of cells.

Sub ClearAllCheckboxes() Dim Answer As String Dim MyNote As String Dim Obj As Object MyNote = "This will Clear all CheckBoxes Proceed? " Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???") If Answer = vbNo Then Exit Sub Else On Error Resume Next For Each Obj In ActiveSheet.OLEObjects Obj.Object.Value = False Next Obj End If End Sub 
+4
source share
2 answers

Try using the topleftcell property:

 Sub ClearAllCheckboxes() Dim Answer As String Dim MyNote As String Dim Obj As Object dim rg as range set rg=selection MyNote = "This will Clear all CheckBoxes Proceed? " Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???") If Answer = vbNo Then Exit Sub Else On Error Resume Next For Each Obj In ActiveSheet.OLEObjects if not intersect(rg, obj.topleftcell) is nothing then _ Obj.Object.Value = False Next Obj End If End Sub 
+1
source
 Obj.TopLeftCell.Column 

will tell you which column the checkbox is in. Based on this, you can decide whether you want to change its value or not.

+1
source

Source: https://habr.com/ru/post/1444165/


All Articles