I have a form where a macro will hide the relevant rows when called. It has multiple checkboxes within the range of rows. I know I can set the CheckBoxes to "Size and Move with Cells" but I do not want them to size with cells as the row needs to be resized to auto fit to the contents and it makes the CheckBox unusable. I also need to loop by row as the CheckBoxes are not within the same column and referencing a specific cell range will force me to rebuild this entire workbook.
I am able to loop through and hide all checkboxes on the sheet, but I need this to only hide CheckBoxes within a certain range of rows. Ideally, I would be able to reference the range in an indexed format to save a few hours of updating work. My current code throws the error "Object or With Variable not set" on the Intersect line. Any way to better reference the control/CheckBox location or even an entirely different method works for me and is much appreciated!
Dim CheckBoxes As OLEObject
Dim xRange As String
Dim r1 As Integer
Dim r2 As Integer
'r1 is beginning of row range, r2 is end of row range.
'I use a formula but I believe it is irrelevant to include it here
r1 = 12
r2 = r1 + 5
xRange = r1 & ":" & r2
For Each CheckBox In ActiveSheet.OLEObjects
If Intersect(CheckBox.TopLeftCell, Range(xRange)) Then ***Error occurs here***
CheckBox.Visible = False
Next
Edit: I am using Excel 2016 if that makes any difference