EDIT
Assign this macro to all form control Checkboxes. The form Control Checkboxes need to be link to the correct row in column BH
. The code checks all filled cells in column BH
and enables or disables all ActiveX checkboxes in the row provided the ActiveX controls have the correct row number at the end of their names (not to be confused with the control's caption). You don't need to add code if you add a new row, just make sure the names of the new controls are correct and this macro is assigned to the form control on the new row.
Sub enableCheckboxes()
'Macro to enable or disable a row of activeX checkboxes based on a cell value in that row
'Declaration of variable
Dim rngLinked As Range, rngRow As Range
Dim enableRow As Boolean
Dim ws As Worksheet
Dim chkBox As oleobject
Dim rowNum As Long, rowNumLength As Long
'Setting of object variables
Set ws = ThisWorkbook.Worksheets("Sheet1") 'Change to the actual name of your sheet.
With ws
Set rngLinked = .Range(.Cells(1, 60), .Cells(.Rows.Count, 60).End(xlUp)) 'Range set to column BH
End With
'Nested loops enable disable objects
Application.ScreenUpdating = False 'Prevent screenupdating
For Each rngRow In rngLinked 'Check column BH
enableRow = rngRow 'See if has to be enabled or not
rowNum = rngRow.Row 'Row to enable or disable
rowNumLength = Len(CStr(rowNum)) 'Used to extract the rownumber from the checkbox' names
For Each chkBox In ws.OLEObjects 'Iterate through the OLE objects on the sheet.
If TypeName(chkBox.Object) = "CheckBox" And CLng(Right(chkBox.Name, rowNumLength)) = rowNum Then 'Check if object is checkbox and is on the current row
If enableRow Then 'Check to enable or disable object
chkBox.Enabled = True
Else
chkBox.Enabled = False
End If
End If
Next chkBox
Next rngRow
Application.ScreenUpdating = True
End Sub
END OF EDIT
You could try something like
Option Explicit
Sub disableAllCheckboxes()
'This sub assumes all checkboxes on the sheet need to be disabled. Add logictests accordingly.
Dim chkBox As OLEObject
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1") 'Replace Sheet1 with the name of your actual worksheet
For Each chkBox In ws.OLEObjects
If TypeName(chkBox.Object) = "CheckBox" Then
chkBox.Enabled = False
End If
Next
End Sub