How to hide Checkbox based on another cell value

gffffdhh 1 Reputation point
2021-06-16T21:26:53.73+00:00

Hi there,

I am creating a fillable excel form.

First question is located in Cell A2. It's a "Yes/No" question. If "Yes" is selected, I want further questions to appear below (including a checkbox). Otherwise if "No" or "Blank" further questions should remain hidden.

I have been able to hide the text/questions through formulas/conditional formatting, but how do I hide Checkboxes through Macros? I don't want to hide the entire row or column.

I am new at this and I have tried the following:

Sub CheckBox1 ( )
If Range("A2").Value = "Yes" Then
ActiveSheet.Shapes("CheckBox1").Visible = True
Else
ActiveSheet.Shapes("CheckBox1").Visible = False
End If
End Sub

Any guidance on the code/how to use Macros would be greatly appreciated!

Developer technologies Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.5K Reputation points
    2021-06-17T05:44:00.837+00:00

    If it is an ActiveX checkbox, then go to Visual Basic, open the worksheet’s code and try adding this fragment:

    Private Sub Worksheet_Change(ByVal Target As Range)
        CheckBox1.Visible = Range("A2").Value = "Yes"
    End Sub
    

    You can also handle the Worksheet_Activate event to set the initial visibility of controls.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.