Trying to have one option button autoselect based on the value of another button

  • Hi there,


    Sample Excel file: [ATTACH]n1224595[/ATTACH]


    I'm new to VBA and am trying to get specific option buttons to autoselect based on the value a user selects for another option button. My code so far is copied below, however, it does not appear to be working. Would greatly appreciate any help!


    Private Sub Worksheet_Change(ByVal Target As Range)
    If ActiveSheet.OptionButton215.Value = xlOn Then
    ActiveSheet.OptionButton231.Value = xlOn
    Else
    ActiveSheet.OptionButton231.Value = xlOff
    End If
    End Sub

  • Hi and Welcome to the Forum :smile:


    To quickly fix your problem ... just attach a sample file ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Thanks for your file


    Since all your options buttons have been grouped ...


    Which one is Option Button 215 and which one is Option Button 231 ...?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • The goal is for when someone selects the 2nd or 3rd option in question 8a, not applicable will autopopulate for 8b and 8c. So for the code I started, option button 215 is the second one under 8a and 231 is the "not applicable" option under 8b. Thanks!

  • Hello again,


    Using Options Buttons from the Forms toolbar is a lot less flexible than ActiveX controls ... :wink:


    Attached is your test file


    Hope this will help

  • Once you have tested the macro ... feel free to share your comments

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Thank you so much, Carim! I was able to apply that code to my main workbook, the only issue is that in my main workbook I can run the macro in the VBA window and it works properly, but if I then select a different response for any of the questions (for instance, selecting the first response for 8a then selecting the second one instead) the macro no longer functions. Is there a way to keep it continuously active like in your spreadsheet? The only part of the code I changed was the cell references based on my main spreadsheet so perhaps I need to change a setting?

  • Glad this helping you out ...


    Should have explained the macro is assigned to your three Options Buttons 8a ...


    Hope this clarifies

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Glad this could help you out ...:wink:


    Thanks for your Thanks AND for the Like ...:smile:

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!