Check all checkboxes only if condition is met

Borm

New Member
Joined
Aug 23, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have this code that checks/unchecks all checkboxes. In column E , based on certain conditions, the cell color becomes red. I am wondering if it's possible to check all checboxes that does not have the cell color red in column E5:E150 ? If a cell color is not ideal , I can enter "False" in the E column.

Any help would be appreciated, thanks

Sub SelectAllSubSector()

Dim cBoxSector As CheckBox

For Each cBoxSector In Worksheets("Input attractivite").CheckBoxes
If Not Intersect(cBoxSector.TopLeftCell, Range("C5:C150")) Is Nothing Then
If cBoxSector.Name <> ActiveSheet.CheckBoxes("Check Box 3").Name Then
cBoxSector.Value = ActiveSheet.CheckBoxes("Check Box 3").Value
End If
End If
Next cBoxSector

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Borm, welcome to MrExcel.

How about
VBA Code:
Sub SelectAllSubSector()

    Dim cBoxSector As CheckBox

    For Each cBoxSector In Worksheets("Input attractivite").CheckBoxes
        If Not Intersect(cBoxSector.TopLeftCell, Range("C5:C150")) Is Nothing Then
            If cBoxSector.Name <> ActiveSheet.CheckBoxes("Check Box 1").Name Then
                cBoxSector.Value = ActiveSheet.CheckBoxes("Check Box 1").Value
            End If
            
        ElseIf Not Intersect(cBoxSector.TopLeftCell, Range("E1:E150")) Is Nothing Then
            With cBoxSector
                If .TopLeftCell.Interior.Color = vbRed Then
                    .Value = False
                Else
                    .Value = True
                End If
            End With
        End If
    Next cBoxSector
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,667
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top