Userform help

Excelnoobisme

Board Regular
Joined
Nov 19, 2010
Messages
128
Hi, i have a simple userform with 2 optionbutton ans 2 textbox.

How can i if, i select the 1st optionbutton the 2 textbook will grey out and lock but when i select the 2nd optionbutton the 2 textbook will unlock
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Use an if statement behind each option button based on change events, like this

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> OptionButton1_Change()<br><SPAN style="color:#00007F">If</SPAN> Me.OptionButton1.Value = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>Me.TextBox1.Locked = <SPAN style="color:#00007F">True</SPAN><br>Me.TextBox2.Locked = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">Else</SPAN><br>Me.TextBox1.Locked = <SPAN style="color:#00007F">False</SPAN><br>Me.TextBox2.Locked = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Thanks, but why is it that when i switch to optionbutton2 i still cant edit textbox after selecting option1button1 1st?
 
Upvote 0
You can set the if statement behind both option buttons like this

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> OptionButton1_Change()<br><SPAN style="color:#00007F">If</SPAN> Me.OptionButton1.Value = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>Me.TextBox1.Locked = <SPAN style="color:#00007F">True</SPAN><br>Me.TextBox2.Locked = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">Else</SPAN><br>Me.TextBox1.Locked = <SPAN style="color:#00007F">False</SPAN><br>Me.TextBox2.Locked = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> OptionButton2_Change()<br><SPAN style="color:#00007F">If</SPAN> Me.OptionButton2.Value = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>Me.TextBox1.Locked = <SPAN style="color:#00007F">True</SPAN><br>Me.TextBox2.Locked = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">Else</SPAN><br>Me.TextBox1.Locked = <SPAN style="color:#00007F">False</SPAN><br>Me.TextBox2.Locked = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
If there are only the two option buttons, OptionButton1_Change will run anytime that OptionButton2 is clicked.
This is all the code that is needed.
Code:
Private Sub OptionButton1_Change()
    TextBox1.Enabled = OptionButton2.Value
End Sub
 
Upvote 0
Sorry, i dont know where went go. Still same problems, when i switch to optionbutton2 i cant edit textbox after selecting option1button1 1st
 
Upvote 0
Hi, i have a simple userform with 2 optionbutton ans 2 textbox.
Oops. The code above got the action of the option buttons wrong way 'round and ignored TextBox 2.
Put this in the userform's code module.
Code:
Private Sub OptionButton1_Change()
    TextBox1.Enabled = OptionButton2.Value
    TextBox2.Enabled = OptionButton2.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,812
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top