ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Option Button and forms (https://www.excelbanter.com/excel-programming/280644-option-button-forms.html)

paradise

Option Button and forms
 
I am having problems with MSForms.OptionButton Function.
I have 5 userforms, and in each form there are 5 option buttons of
which the user select one. The program will need to trace the option
chosen and input it into a worksheet.I have used the below stated code
but it doesn't work for userform 2, 3, 4, and 5. It seems to be able
to work for the first form-userForm1. Any help is appreciated.

Private Sub OptionButton1 Click()
setoption
End Sub
Private Sub OptionButton2 Click()
setoption
End Sub
Private Sub OptionButton3 Click()
setoption
End Sub
Sub setoption()
Dim c As Control
For Each c In Controls
If TypeOf c Is MSForms.OptionButton Then
If c Then
Range("A1") = c.Tag
Exit For
End If
End If
Next
End Sub

Tom Ogilvy

Option Button and forms
 
Try telling it which userform:

Private Sub OptionButton1 Click()
setoption Userform2
End Sub
Private Sub OptionButton2 Click()
setoption Userform2
End Sub
Private Sub OptionButton3 Click()
setoption Userform2
End Sub
Sub setoption(Uform as Object)
Dim c As Control
For Each c In Uform.Controls
If TypeOf c Is MSForms.OptionButton Then
If c Then
Range("A1") = c.Tag
Exit For
End If
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"paradise" wrote in message
om...
I am having problems with MSForms.OptionButton Function.
I have 5 userforms, and in each form there are 5 option buttons of
which the user select one. The program will need to trace the option
chosen and input it into a worksheet.I have used the below stated code
but it doesn't work for userform 2, 3, 4, and 5. It seems to be able
to work for the first form-userForm1. Any help is appreciated.

Private Sub OptionButton1 Click()
setoption
End Sub
Private Sub OptionButton2 Click()
setoption
End Sub
Private Sub OptionButton3 Click()
setoption
End Sub
Sub setoption()
Dim c As Control
For Each c In Controls
If TypeOf c Is MSForms.OptionButton Then
If c Then
Range("A1") = c.Tag
Exit For
End If
End If
Next
End Sub





All times are GMT +1. The time now is 03:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com