I am creating a VBA macro to select all checkboxes in a sheet and it works fine but now i want to adjust my code to select and unselect just the checkboxes in a particular range.
Here is my code.
Sub Select_all()
Dim Cbox As CheckBox
Dim Rng As Range
Set Rng = ActiveWorkbook.Sheets("Sheet4").Range("B7, B104")
For Each Cbox In ActiveSheet.CheckBoxes
If Not Intersect(Cbox.TopLeftCell, Rng) Is Nothing Then
If Cbox.name <> ActiveSheet.CheckBoxes("Check Box 104").name Then
Cbox.Value = ActiveSheet.CheckBoxes("Check Box 104").Value
End If
End If
Next Cbox
End Sub
I added
If Not Intersect(Cbox.TopLeftCell, Rng) Is Nothing
but it doesn't change anything, and when i remove this part then it selects all the checkboxes in the sheet and i need only for the Range("B7:B104")
Any suggestions please ? Thank you very much.
Range("B7, B104")? That means it is only two cells, B7 and B104, not the range of cells B7:B104. And then just under your code you put the correct definition ofRange("B7:B104"), so just change to that.