Hiding rows by a logic formula
I tried to enter the code as you suggested and have
encountered a run time error 'object required' The second
line of code is highlighted, which leads me to believe
that I do not have the name of the check box correct...?
It seems silly, but I could not find a way to check its
name, I just recall what was written in the text when I
first inserted it. Could this be my problem?
I have named the rows that I would like hidden "ExtraRows"
like you suggested and my sheet name is "Main".
Here is what I have in the code...
Private Sub CheckBox31_Change()
If CheckBox31.Value Then 'checkbox is ticked
Sheets("Main").Range("ExtraRows").EntireRow.Hidden
= False
Else
Sheets("Main").Range("ExtraRows").EntireRow.Hidden
= True
End If
End Sub
This is in a module, not a class module. Does that matter?
Sorry - didn't realise that controls placed on a worksheet behave
differently than controls placed on a userform. So:
Go to the visual basic editor (tools-macro-visual basic editor), double
click on the sheet your control is in.
add:
Sub ShowHideRows()
If CheckBox31.Value Then 'checkbox is ticked
Sheets("Main").Range("ExtraRows").EntireRow.Hidden = False
Else
Sheets("Main").Range("ExtraRows").EntireRow.Hidden = True
End If
End Sub
Close the visual basic editor. On your sheet, right click the checkbox -
Assign Macro...
assign it the above macro.
Iain
|