Userform Problem

zyhin

Board Regular
Joined
Oct 8, 2009
Messages
78
Hi all,

Hoping someone can help me. I have a userform that has 2 text boxes and 9 option buttons in a frame. Is there any way to stop text being entered when a option button has been pressed and vice versa.

Zyhin
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Assuming:

- Your TextBoxes are named TextBox1 and TextBox2
- Your 9 OptionButtons are named OptionButton1, OptionButton2, and so on until OptionButton9
- If any OptionButton is selected (True) then you do not want any new text to be added to either TextBox

Then

This in the userform module would work:


Code:
 Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim iOpt%
For iOpt = 1 To 9
If Controls("OptionButton" & iOpt).Value = True Then
KeyAscii = 0
Exit For
End If
Next iOpt
End Sub
 
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim iOpt%
For iOpt = 1 To 9
If Controls("OptionButton" & iOpt).Value = True Then
KeyAscii = 0
Exit For
End If
Next iOpt
End Sub
 
Upvote 0
Thanks Tom...Works well...Just wish I understood it...lol

Makes sense to me except the first line. Being new to VBA don't help

Thank again

Zyhin
 
Upvote 0
Try and try..I cant get the code to work Vise versa.

I put this code in for each option button and changed the code to textboxes. However the first line is got me stumped. Am I on the right track or going wrong.

Code:
Private Sub OptionButton1_Click(ByVal KeyAscii As MSForms.ReturnInteger)
Dim iTxt%
For iTxt = 1 To 2
If Controls("TextBox" & iOpTxt).Value = True Then
KeyAscii = 0
Exit For
End If
Next iTxt
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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