• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Loop to hide checkboxes based on cell value

jho78

New Member
Hi

I'm trying to create a procedure to hide a number of checkboxes based on if column A is empty or not. So if for a single check box I've used

>>> use code - tags <<<
Code:
If Range("A11").Value = "" Then
ActiveSheet.CheckBoxes("Check Box 2").Visible = False
Else
ActiveSheet.CheckBoxes("Check Box 2").Visible = True
End If
I would like to loop through rows (11 to 62) and hide/show the checkboxes in those rows.

Thanks for any help.
 
Last edited by a moderator:
Hi,

I've attached a basic file that has the elements needed on the sheet.
 

Attachments

  • Checkbox Hide.xlsm
    33.4 KB · Views: 10
For the file you've attached...
With your check boxes nicely arranged numerically like that, this works for me
Code:
Sub ChkBoxHide()
    Dim i As Long
    
For i = 11 To 40
    If Range("A" & i).Value = "" Then
        ActiveSheet.CheckBoxes("Check Box " & i - 10).Visible = False
    Else
        ActiveSheet.CheckBoxes("Check Box " & i - 10).Visible = True
    End If
Next i

End Sub

but if you didn't know the arrangement of the check boxes you would need to go by the .TopLeftCell of the check boxes and all of yours are actually in the row above where they appear to be.
 
Amazing. Thank you. I was trying to use .TopLeftCell but couldn't get my head around it to make it work.
 
Back
Top