• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Code conflicts

ranaray

Member
I have inserted a radio button that hides rows (3:10). In the same spreadsheet I have inserted codes that need to unhide row (4:4) if I select "yes" from range("A1).


The radio button works perfect , however the second code to unhide row (4:4) based on list selection is not working. I think its because the list selection code cant override the radio button code.


Any advice will be much appreciated. reaching the frustration point now.
 
The below code is to manage the radio buttons


Sub question9y()

'

' question9 Macro

'

Rows("17:20").EntireRow.Hidden = False

Rows("26:32").EntireRow.Hidden = False

Rows("22:25").EntireRow.Hidden = True

Rows("33:38").EntireRow.Hidden = True

'


End Sub

Sub question9n()

'

' question9n Macro

'

Rows("17:38").EntireRow.Hidden = True


End Sub

Sub question10y()

'

' question10y Macro

'

Rows("22:22").EntireRow.Hidden = False

Rows("17:21").EntireRow.Hidden = True

Rows("23:38").EntireRow.Hidden = True


End Sub

Sub question10n()

'

' question10n Macro

Rows("17:38").EntireRow.Hidden = True


End Sub

-----------------------------------------------------------------

The below code is when I rightclick on the sheet I am working and select 'View Code'

Please note all this is happening in the same sheet.


Private Sub OptionButton1_Click()

question9y

End Sub


Private Sub OptionButton2_Click()

question9n

End Sub


Private Sub OptionButton3_Click()

question10y

End Sub


Private Sub OptionButton4_Click()

question10n

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)


If Range("k18") = "no" Then

Rows("19:19").EntireRow.Hidden = True

If Range("k18") = "yes" Then

Rows("19:19").EntireRow.Hidden = False

End If

End Sub
 
Hi ,


Change your code for the Worksheet_Change event to :

[pre]
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("k18") = "no" Then
Range("19:19").EntireRow.Hidden = True
End If

If Range("k18") = "yes" Then
Range("19:19").EntireRow.Hidden = False
End If
End Sub
[/pre]
Narayan
 
Hi, ranaray!

Another approach might be changing the 2nd "If" by an "ElseIf" in the change event code.

Regards!

PS: A good practice is always to compile the code to check design time errors (from the VBE menu, Debug, Compile VBA Project), in this case a message "If block without EndIf" should have been displayed.
 
Back
Top