Consulting

Results 1 to 2 of 2

Thread: One OptionButton change state of another one in different group

  1. #1
    VBAX Regular
    Joined
    Jan 2021
    Posts
    65
    Location

    One OptionButton change state of another one in different group

    Can someone write me a VBA code for Excel OptionButton. I have multiple groups with OptionButtons and depending of the state of those OptionButtons some parts of worksheet are hidden or showed (with hiding rows macro). The problem is that some of the options are opposite one to another so I need code that will for example set Option button in "group 2" to 2 if OptionButton in "group 1" is set to 1.
    I attached file with example and what I want is:


    1. if in "group1" is selected Option 1 ------> show "group 2" with Option 3 and 4 and set Option 4 as active (with possibility to change Option), (when Option 4 is selected that will run code that will hide "group 3" until user change that)
    2. If in "group1" is selected Option 2-------> hide "group 2" with Option 3 and 4 but set Option 3 as active (that will run code that will show group 3)


    Im not good in programming so if anyone know better solution for this problem feel free to post it.
    Proba.xlsm

  2. #2
    VBAX Regular
    Joined
    Jan 2021
    Posts
    65
    Location
    Maybe I could explain it in a simpler way.
    If in Group 1 is selected OptionButton1 then in Group 2 must be selected OptionButton2 otherwise I have conflict in my code. I use this code to show or hide rows and this is example of code I use for hiding rows.


    Sub testCode()
    Set OptBtns = Me.OptionButtons
    Rows("10:20").EntireRow.Hidden = Not (OptBtns("Gumb mogućnosti 1").Value = 1)
    Rows("21:30").EntireRow.Hidden = Not (OptBtns("Gumb mogućnosti 2").Value = 1)
    Rows("31:40").EntireRow.Hidden = Not (OptBtns("Gumb mogućnosti 3").Value = 1)
    End Sub

    And in this code I need to "Gumb mogućnosti 1" have value "2" if "Gumb mogućnosti 3" have value "1".
    Anyone have any idea?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •