Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need the checkbox "Two_one_WP" to be hidden until checkbox "Two_zero" is clicked any ideas???

What I have tried:

VB
Private Sub Two_zero_Click()
If Two_zero = True Then
    [2].EntireRow.Hidden = False
    Else: [2].EntireRow.Hidden = True
    End If
End Sub

Private Sub Two_one_WP_Click()
If Two_one_WP = True Then
    [3:7].EntireRow.Hidden = False
    Else: [3:7].EntireRow.Hidden = True
    End If
End Sub
Posted
Updated 17-Jan-18 1:19am
v2

1 solution

Why are you trying to hide rows on the spreadsheet?

Just toggle the Visible property of the Checkbox, e.g. putting this code into the ThisWorkbook VBA module works for me
VB
Option Explicit

Private Sub Two_zero_Click()
    If Two_zero.Value Then
        two_one_WP.Visible = True
    Else
        two_one_WP.Visible = False
    End If
End Sub

It's worth noting that the Checkbox objects I used were the ActiveX controls not the Form Controls. If you use the Form Controls then you need something like this instead
VB
Sub Two_zero_Click()
    If ActiveSheet.Shapes("Two_zero").ControlFormat.Value = 1 Then
        Sheets("Sheet1").Shapes("two_one_WP").Visible = True
    Else
        Sheets("Sheet1").Shapes("two_one_WP").Visible = False
    End If
End Sub


[Edit after OP comment]

You claim that the code above "disrupts" your code to hide rows. It can't.

If you want all the sub-category checkboxes to also disappear then you could just expand the code I've given you to include all of them. There is nothing to stop you hiding the rows as well if that is what you want to do.

However, if you are trying to hide the checkboxes by hiding the rows that they are on then you need to set them to "Move and Size with Cells". The accepted answer on this StackOverflow post[^] will show you how to do that (it depends on which version of Excel you are using).
Once you have set that property on the checkbox(es) then when you hide a row the checkbox "on" that row will also be hidden.
 
Share this answer
 
v2
Comments
Maciej Los 17-Jan-18 7:21am    
Caroline, seems OP wants to hide rows... This piece of code might be important: [3:7].EntireRow.Hidden = True
CHill60 18-Jan-18 5:29am    
I think I see what their problem is (updated solution) ... but they did ask how to make checkboxes hidden ;-)
Maciej Los 20-Jan-18 1:54am    
5ed!
Member 13626605 17-Jan-18 18:30pm    
Im creating a spreadsheet and have a checkbox for each catagory and when that checkbox is clicked it opens a series of subcatagories that can be clicked to provide additional information. I need the VBA code to make all subcatagory check box disapear as well as the rows until the catagory is picked then each of the subcatagories can be clicked to provide the detail information.
I have this code to hide the rows until the checkbox has been clicked. The above code to hide the check box seems to work but it disrupts my original code to hide the rows for the subcatagories? Any suggestions?
Private Sub CheckBox2_Click()
If CheckBox2 = True Then
[262:266].EntireRow.Hidden = False
Else: [262:266].EntireRow.Hidden = True
End If
End Sub
Thanks you in advance!
CHill60 18-Jan-18 5:29am    
I've update my solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900