How do I get Excel to display a range of cells with a check box?

B

bobm

I am trying to get excel to disply a range of cells when a check box is
checked and hide them when it is not checked.
 
C

Casey

bobm,

I am not one of the VBA experts, but if your range is in a column and
your checkbox is from the control toolbox and not from the Forms
toolbar this code should work.

Private Sub CheckBox1_Click()
Dim i As Boolean
Dim rng1 As Range

Application.DisplayAlerts = False
i = CheckBox1.Value
Set rng1 = Range("D1:D25") 'Change to suit your needs

If i = True Then
rng1.EntireColumn.Hidden = True
Else
rng1.EntireColumn.Hidden = False
End If
Application.DisplayAlerts = True

End Sub
 
D

Dave Peterson

I put a checkbox from the control toolbox toolbar on a worksheet.

I doubleclicked on that checkbox (named checkbox1) and put this code in that
visible code window:

Option Explicit
Private Sub CheckBox1_Click()
Dim myRng As Range
Set myRng = Me.Range("a10:A20").EntireRow
myRng.Hidden = Me.CheckBox1.Value
End Sub

Then back to excel (click on that design mode icon also on the control toolbox
toolbar) and try checking that box.
 
Top