• 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.

Deactivate option button and cell

Hi friends,

What I need to do is,
- If fruits is selected in question 1,
then automatically OptionButton3, OptionButton4 & OptionButton5 should get activated
and OptionButton6, OptionButton7 and cell E9 should get deactivated (means user should be restricted to use them).
- if vegetables is selected in qusetion1 ,
then automatically OptionButton6, OptionButton7 and cell E9 should get activated
and OptionButton3, OptionButton4 & OptionButton5 should get deactivated

I have used activeX option buttons as that is the requirement from my boss.
I tried to use If-Then-Else but its not working :( .

Link for sample file
 

Attachments

  • Option button deactivation.xlsm
    20.5 KB · Views: 2
To keep away the nuances of sheet protection and cell locking, I would suggest using a text box.

And just use this code in the respective sheet module

Code:
Private Sub OptionButton1_Change()

    Me.OLEObjects(Array("OptionButton3", "OptionButton4", "OptionButton5")).Enabled = Me.OptionButton1.Value
    Me.OLEObjects(Array("OptionButton6", "OptionButton7", "TextBox1")).Enabled = Not Me.OptionButton1.Value
    
End Sub
 

Attachments

  • Option button deactivation.xlsm
    34.3 KB · Views: 2
Hi Sam, if you don't mind can you please tell me
  • why we are using Me.OLEObjects and not just Me.objects
  • what is the use of Me
 
mani_bbc05, sorry for being cryptic there.

the Me that I used for your solution was referring to the parent sheet where you had those option buttons. Any class object that offers a code module can be referred to within that code module as Me

In an Excel VBA project, the code modules for Sheet, UserForm, Workbook and custom class allow for using Me

Now, the activex controls like option buttons, text boxes etc fall under the OLEObjects collection. On the other hand, there is no collection called Objects, but only an Object which is used to define the class
 
mani_bbc05, sorry for being cryptic there.

the Me that I used for your solution was referring to the parent sheet where you had those option buttons. Any class object that offers a code module can be referred to within that code module as Me

In an Excel VBA project, the code modules for Sheet, UserForm, Workbook and custom class allow for using Me

Now, the activex controls like option buttons, text boxes etc fall under the OLEObjects collection. On the other hand, there is no collection called Objects, but only an Object which is used to define the class

Thanks a lot Sam for the explanation :) .​
 
Back
Top