Hide Rows Using Checkbox

B

BJ

I'd like to hide rows in tab 'Output' based on a checkbox in tab 'Input' ...
I've tried the code below but am getting the Run-time erro 1004 - Select
Method of Range class failed. So obviously I'm not calling this correctly.
Any help? Thanks.

Private Sub checkbox3_Click()
If CheckBox3 = True Then
Sheets("Output").Select
Rows("14:14").Select
Selection.EntireRow.Hidden = False
End If
If CheckBox3 = False Then
Sheets("Output").Select
Rows("14:14").Select
Selection.EntireRow.Hidden = True
End If
End Sub
 
F

FSt1

hi
i think it has to do with a sheet thing. the comboboxes are assigned to a
sheet and you are wanting to move to another sheet so try it without all the
selecting.
Private Sub checkbox3_Click()
If CheckBox3 = True Then
Sheets("Output").Rows("14:14").EntireRow.Hidden = False
End If
If CheckBox3 = False Then
Sheets("Output").Rows("14:14").EntireRow.Hidden = True
End If
End Sub

tested. works in 03

Regards
FSt1
 
J

JLGWhiz

Private Sub checkbox3_Click()
If Sheets(Input).CheckBox3 = True Then
Sheets("Output").Rows(14).Hidden = False
End If
If CheckBox3 = False Then
Sheets("Output").Rows(14).Hidden = True
End If
End Sub

Range("14:14")
Rows(14)
 
D

Dave Peterson

Just to add...

Since this code is behind a worksheet, the unqualified ranges (rows(14:14)) will
belong to the sheet that owns the code. And since you can only select a range
on the activesheet, your code fails.

You could have used:

If CheckBox3 = True Then
with sheets("Output")
.select
.rows("14:14").select
selection.entirerow.hidden = false
end with
else...

But it's better not to select anything in your code. The resulting code will be
much easier to read.

I would have used something like:

Private Sub checkbox3_Click()
workSheets("Output").Rows(14).EntireRow.Hidden = Not (CheckBox3.Value)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top