Assign values to ratio buttons (1 Viewer)

akhlaq768

Registered User.
Local time
Today, 13:10
Joined
Jan 17, 2008
Messages
42
I have created a UserForm in Excel, to gather data for a questionnaire.

For each question, the user must select an answer from a radio button (Yes, No and N/A)

When I add the record (answers) to the sheet1, the results are shown as all being false.

I want to show either ‘Yes’ or ‘No’ or ‘N/A’

How do I do this????

Code:
Private Sub CommandButton2_Click():

Dim LastRow As Object

Set LastRow = Sheet1.Range("a65536").End(xlUp)

LastRow.Offset(1, 1).Value = UserForm1.OptionButton1.Value 
LastRow.Offset(1, 1).Value = UserForm1.OptionButton2.Value
LastRow.Offset(1, 1).Value = UserForm1.OptionButton3.Value

End Sub

Thanks in advance
 

Attachments

  • AuditForm.zip
    23.9 KB · Views: 169

chergh

blah
Local time
Today, 13:10
Joined
Jun 15, 2004
Messages
1,414
Radio button values are boolean and the "yes" "no" "n/a" are labels rather than values.

With your code:

Code:
UserForm1.OptionButton1.Value

You are always referring to the "yes" radio button on Q1 so if it is selected the value will be true and if it is not selected the value will be false. Optionbutton2 like wise will always refer to the "no" radion button on Q1 and optionbutton3 the "N/A" radiobutton with their values being "true" or "false" depending upon if they are selected or not.

If you wish to use your current form then you need to add something like:

Code:
if userform1.optionbutton1.value = true then
   LastRow.Offset(1, 1).Value = "yes"
elseif userform1.optionbutton2.value = true then
   LastRow.Offset(1, 1).Value = "no"
elseif userform1.optionbutton3.value = true then
   Lastrow.Offset(1, 1).Value = "N/A" 
end if

You will need to use code like this for each question in your userforms.
 

Users who are viewing this thread

Top Bottom