option button (yes No) to hide rows

W

Wanna Learn

Hello I have two option buttons one says yes the other No
SO if the option selected is yes I want to unhide row A32 thruA44 if No is
selected then rows A32 thru A44 remain hidden
this is what I have but it does not work
Private Sub OptionButton1_Click()
Dim myRng As Range

Set myRng = Me.Range("a32:a44")

myRng.EntireRow.Hidden = Not (myRng(1).EntireRow.Hidden)

End Sub
thanks for your help
 
L

Luke M

You could simplify it to:

Private Sub OptionButton1_Click()
Range("A32:A44").EntireRow.Hidden = Not (Range("A32:A44").EntireRow.Hidden)
End Sub
 
W

Wanna Learn

Thanks Luke
This works fine but If I select the "NO" command button nothing happens . If
No is selected I want the rows a32 to A44 remain hidden. (I cannot deselect
Yes) Thanks again
 
L

Luke M

Assuming your buttons are labeled 1 and 2 respectively:

Private Sub OptionButton1_Click()
'This is the "YES" button
Range("A32:A44").EntireRow.Hidden = True
End sub

Private Sub OptionButton2_Click()
'This is the "NO" button
Range("A32:A44").EntireRow.Hidden = False
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