Through a command button hiding rows

  • Thread starter Thread starter Saz
  • Start date Start date
S

Saz

Help!
I am creating a workbook where in worksheet1 there is a checklist
Ideally when a topic's checkbox is clicked, a macro (which I hav
assigned) will hide certain rows on worksheet2.
However I cannot get the action to reverse when the box is unchecked.
This is really frustrating me as I have tried to write a program usin
boolean instead of the macro for when the button is "clicked" and the
clicked again, but I am not getting anywhere.

If it helps the rows I have also grouped into arrays.

Below is like my 20th attempt

Private Sub CheckBox1_Click()
Sheets("Sheet1").Select
i = Rows("13:22")
i.Select
Selection.EntireRow.Hidden = True
Sheets("Sheet2").Select

End Sub;
 
Private Sub CheckBox1_Click()
Worksheets("Sheet1").Rows("13:22").hidden = True
End Sub

HTH
 
If you want them hidden when the checkbox is checked and unhidden when it is
unchecked then

Private Sub CheckBox1_Click()
Set rng = Sheets("Sheet1").Rows("13:22")
rng.Hidden = CheckBox1.Value
End Sub

for the opposite:


Private Sub CheckBox1_Click()
Set rng = Sheets("Sheet1").Rows("13:22")
rng.Hidden = Not CheckBox1.Value
End Sub
 
Private Sub CheckBox1_Click()
WorkSheets("Sheet1").Rows("13:22").Hidden = CheckBox1.Value
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Tom I have tried yours but it will not allow both together as an erro
occurs stating ambigious error detected as CheckBox1_Click is alread
being used. I want to use both of your programs that you have create
for the checkbox. Do you know how?

Thanks;)

Tom said:
If you want them hidden when the checkbox is checked and unhidden whe
it is
unchecked then

Private Sub CheckBox1_Click()
Set rng = Sheets("Sheet1").Rows("13:22")
rng.Hidden = CheckBox1.Value
End Sub

for the opposite:


Private Sub CheckBox1_Click()
Set rng = Sheets("Sheet1").Rows("13:22")
rng.Hidden = Not CheckBox1.Value
End Sub

--
Regards,
Tom Ogilvy
 
I don't think you understand the code. Either want them hidden when it is
checked or you want them unhidden when it is checked. Both codes will handle
both checking and unchecking. The first hides them when it is checked and
unhides them when it is unchecked - both actions trigger the click event.
The second does the opposite - so you only need one.
 
I used yours and at first tried to use both programs you provided at the
same time, but found that the first one on its own worked perfectly!

Cheers Honey!
 

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

Back
Top