Home > Enterprise >  The option button does not switch on and off by changing the pull-down content
The option button does not switch on and off by changing the pull-down content

Time:05-19

I want to switch the two option buttons on and off when I change the contents of the pull-down.
However, the code I wrote doesn't change the options button at all.
Do you have any advice?

Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$H$21" Then
    Select Case Target.Value
      Case "A"
        Option1.Value = True
        Option2.Value = False
      Case "B"
        Option1.Value = False
        Option2.Value = True
      Case "C"
        Option1.Value = False
        Option2.Value = False
    End Select
  End If
End Sub

CodePudding user response:

I think your code is working just fine. The problem is probably that you are still in "Design Mode", which is the mode you enter when you add a Option Button (or some other one) and you need to exit it explicitly in order for your VBA code to be able to run again.

Go to the tab "Developers". Under "Controls" you'll see "Design Mode". Make sure to turn it off. Code should work now.

Design Mode

You can also find the same icon in your VBA editor. It should be in the standard ribbon there.

  • Related