PDA

View Full Version : One OptionButton change state of another one in different group



hrzagi
09-16-2021, 01:51 AM
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.
28974

hrzagi
09-20-2021, 03:42 AM
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?