PDA

View Full Version : [SOLVED] UserForm Radio Buttons



fredlo2010
05-21-2012, 09:19 PM
Hello guys,

OK I am trying to create this form that will perform an operation based on a radio button selection.

http://i49.tinypic.com/2ed1c7n.jpg

I want to select an option and press one of the buttons to the left that will run a code according to my selection.

Example:

If I select Option 1 and press the Add Button: I will go to column option1 in my active sheet and copy it and paste it in a new place in the document.


If I select Option 3 and press Append Button: I will go to to Column Option3 in my active sheet and copy it and paste it in a new place in the document and then remove duplicates.



I am sorry for been a little ambiguous here but I am totally blind here.

any help will be appreciated

Thanks a lot

snb
05-21-2012, 11:57 PM
I want to select an option and press one of the buttons to the left ???

I am totally blind here

Tinbendr
05-22-2012, 01:59 AM
The way I handle option buttons is to assign a value the tag property of the object, in this case, the Page.

Anytime you select an option button (or any object really), it triggers an event. Using this event, it gives the opportunity to do other stuff.


Private Sub OptionButton1_Click()
Me.MultiPage1.Tag = "1"
End Sub

Private Sub OptionButton2_Click()
Me.MultiPage1.Tag = "2"
End Sub

'etc


Then, when you click the commandbutton E.g. the Add button.


Private Sub CommandButton1_Click()
Select Case Me.MultiPage1.Tag
Case "1"
'Copy data from Range "A"
Case "2"
'Copy data from Range "B"
Case "3"
'Copy data from Range "C"
End Select
End Sub


Double click the objects on the userform to automatically add these blank events to the code page.

HTH

fredlo2010
05-26-2012, 10:39 PM
Thanks

here is my code :


Private Sub CommandButton1_Click()
If SetA1 = True Then
Call AddSystems("A")
ElseIf SetA2 = True Then
Call AddSystems("B")
ElseIf SetA3 = True Then
Call AddSystems("C")
ElseIf SetA4 = True Then
Call AddSystems("D")
ElseIf SetA5 = True Then
Call AddSystems("E")
ElseIf SetB1 = True Then
Call AddSystems("F")
ElseIf SetB2 = True Then
Call AddSystems("G")
ElseIf SetB3 = True Then
Call AddSystems("H")
ElseIf SetB4 = True Then
Call AddSystems("I")
ElseIf SetB5 = True Then
Call AddSystems("J")

mikerickson
05-27-2012, 12:22 AM
Private Sub CommandButton1_Click()
Select Case True
Case OptionButton1.Value
Rem do one thing
Case OptionButton2.Value
Rem do another thing
Case OptionButton3.Value
Rem do a third thing
End Select
End Sub

fredlo2010
05-28-2012, 05:36 PM
Hi mikerickson,

Thanks for the help. Is there a difference between "Select Case" and " If...ElseIf" statements?