MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Hiding a Range Depending Upon User Selection

February 11, 2002 - by Juan Pablo Gonzalez

Mike asks:

In my workbook, if a control checkbox is not checked then I would like to hide specific rows and columns automatically with VBA. How is this done? Thank you.

Being a Control checkbox, you would have code that looks like this:

Private Sub CheckBox1_Click()
	Rows(15).Hidden = CheckBox1
End Sub

The first part is to avoid an error IF you are using Excel 97. The second line is an "improved" IF, it could be made like this:

If CheckBox1 = True then
	Rows(15).Hidden = True
	Rows(15).Hidden = False
End If

But why do all the extra typing?