VB Loop to hide check box when associated row is hidden

mjlex

New Member
Joined
May 31, 2013
Messages
4
I have an excel 2010 workbook that include 3 sheets. The first sheet allows the user to select via checkbox the categories that will appear on the second sheet, and the second sheet will then allow the user to select from options within the categories limited by the first sheet to determine the output on the third sheet.

When the user selects certain checkboxes on the first sheet, there are associated cells in the second sheet that populate with a true or false value. The present script then runs via a controlbutton to hide the rows with a false value on the second sheet. There are two rows with no checkboxes between each category, one is blank, and the other is the next category title, so I have 4 rows of options with a checkbox assigned to each row, then 1 blank row, a title row, then a series of 4 more options with checkboxes, and so on for about 75 rows.

My problem is that while rows 10-13 are associated with checkboxes 1-4, checkbox 5 doesn't appear until row 16 because of the 2 'unselectable' rows between options, so I can't figure out how to loop the object hide to make the unnecessary checkboxes invisible. Right now I'm building an If statement for each row/checkbox, and it's slowly driving me insane. My code looks like this:

Code:
If ActiveSheet.Rows("10").Hidden = True Then
    ActiveSheet.CheckBox1.Visible = False
    Else: ActiveSheet.CheckBox1.Visible = True
    End If
    
    If ActiveSheet.Rows("11").Hidden = True Then
    ActiveSheet.CheckBox2.Visible = False
    Else: ActiveSheet.CheckBox2.Visible = True
    End If
    
    If ActiveSheet.Rows("12").Hidden = True Then
    ActiveSheet.CheckBox3.Visible = False
    Else: ActiveSheet.CheckBox3.Visible = True
    End If
    
    If ActiveSheet.Rows("13").Hidden = True Then
    ActiveSheet.CheckBox4.Visible = False
    Else: ActiveSheet.CheckBox4.Visible = True
    End If
    
    If ActiveSheet.Rows("16").Hidden = True Then
    ActiveSheet.CheckBox5.Visible = False
    Else: ActiveSheet.CheckBox5.Visible = True
    End If

Does anyone know how I could make a loop that would determine whether to hide checkboxes 1-4 based on the visibility of rows 10-13, then skip rows 14 and 15, then check checkboxes 5-8 based on rows 16-19, then skip rows 20 and 21, and so on? There are not always 4 rows in a category, sometimes there are 3 or 5, which could add another level of difficulty. Please help so I don't have to put in 50 If statements!

Let me know if you need any further explanation, though I feel like I may have overexplained a bit. Thank you!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I am not sure if I can quickly make your loop, but your logic can be improved upon greatly:
Code:
with ActiveSheet             ' so you don't have to repeat 'Activesheet' all the time
      .CheckBox1.Visible = Not .Rows(10).Hidden
      .CheckBox2.Visible = Not .Rows(11).Hidden
      .CheckBox3.Visible = Not .Rows(12).Hidden
      .CheckBox4.Visible = Not .Rows(13).Hidden
      .CheckBox5.Visible = Not .Rows(16).Hidden
end with
 
Upvote 0
That's a fantastic start, thank you! I'm brand new to this, so I'm stumbling through it and anything helps.
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,400
Members
449,448
Latest member
Andrew Slatter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top