View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default 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