Survey with more than 2 options

rpolasky

New Member
Joined
Mar 29, 2013
Messages
18
Hey guys/gals,

I followed a youtube video on setting up a survey in excel, and it works great, but it was only for two options. I wanted to make it 5 options per question, but when I started adding to the code ( which I thought was correct, but was not ) I kept getting errors. It probably is a simple addition. Any thoughts on how to make the survey options more than two?

There are three tabs. The first tab (Start) only has a button that leads to the QA Survey. The Second tab has the questions and answers. The third tab as three columns in it as well for the name of the person, question number, and answer choice.

Here is the code inside the form (QASurvey):
Code:
Private Sub button_next_Click()
''confirm there is a name
If TextBox1.Value = "" Then
MsgBox ("Please enter your name")
Exit Sub
End If
''confirm there is an answer
If rda.Value = False And rdb.Value = False Then
MsgBox ("Please select an answer")
Exit Sub
End If
''enter the name, question, and answer into results array
results(questionnumber - 1, 0) = QASurvey.TextBox1.Value
results(questionnumber - 1, 1) = questionnumber
If rda.Value = True Then
results(questionnumber - 1, 2) = "A" 'could put rda.caption
Else
results(questionnumber - 1, 2) = "B"
End If
''set the radio button to empty
rda.Value = False
rdb.Value = False
''populate the form with the next question
If questionnumber = UBound(info) + 1 Then
''stop
Call enterresults
MsgBox ("Thank You for completing the survey")
Unload QASurvey
Else
''populate next question
QASurvey.Label_question.Caption = info(questionnumber, 0)
QASurvey.rda.Caption = info(questionnumber, 1)
QASurvey.rdb.Caption = info(questionnumber, 2)
End If
questionnumber = questionnumber + 1

End Sub
Sub enterresults()
Sheets("results").Select
Range("a2:c1000").ClearContents
''loop through results array
r = 2
For i = 0 To UBound(results)
Cells(r, 1).Value = results(i, 0)
Cells(r, 2).Value = results(i, 1)
Cells(r, 3).Value = results(i, 2)
r = r + 1
Next i
End Sub
Private Sub UserForm_Initialize()
Sheets("questions").Select
r = Range("a1").End(xlDown).Row - 1
ReDim info(r - 1, 3) 'redim 2 dimensional array
ReDim results(r - 1, 2) 'redim 2 dimensional array
'' fill a 2d array
r = 2
i = 0
Do Until Cells(r, 1).Value = ""
info(i, 0) = Cells(r, 1).Value
info(i, 1) = Cells(r, 2).Value
info(i, 2) = Cells(r, 3).Value
r = r + 1
i = i + 1
Loop
''populate the userform with data
QASurvey.Label_question.Caption = info(0, 0)
QASurvey.rda.Caption = info(0, 1)
QASurvey.rdb.Caption = info(0, 2)

questionnumber = 1
End Sub


Here is the code in Module 1:

Code:
''global variables
Public info() As Variant
Public results() As Variant
Public questionnumber As Integer

Here is the code on the sheet that has the button to start the Survey Form:

Code:
Private Sub Start_Button_Click()
QASurvey.Show
End Sub

*EDITED TO ADD IN THE "CODE,/CODE" LINES
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Not sure if I can help, however I can see that the question sheets the userform and the code will all have to be changed to expand the survey. I try to recreate the file but you haven't give enough info in your example and I couldn't find the utube vid to match your example.

You could upload the file to https://www.sendspace.com/ so people could have a look in the post

Cheers
 
Upvote 0
Thanks for the reply. Here is the video I used to create the product: https://www.youtube.com/watch?v=BxgRlDIHpxI

Sadly, I'm on a gov computer and cannot upload anything. The only different thing I changed from the video is that the video also adds a picture to the survey, and I didnt need that so I ommitted that portion.
 
Upvote 0
I think it might have to be something to do with this portion of the code:

Code:
''enter the name, question, and answer into results array
results(questionnumber - 1, 0) = QASurvey.TextBox1.Value
results(questionnumber - 1, 1) = questionnumber
If rda.Value = True Then
results(questionnumber - 1, 2) = "A" 'could put rda.caption
Else
results(questionnumber - 1, 2) = "B"
End If

and this portion of the code:

Code:
''populate next question
QASurvey.Label_question.Caption = info(questionnumber, 0)
QASurvey.rda.Caption = info(questionnumber, 1)
QASurvey.rdb.Caption = info(questionnumber, 2)
End If


I tried to use another "else" in the first portion but it came back with an error. The 'rda' and 'rdb' are the two options that I want to expand upon option 3 would have been 'rdc' etc...
 
Upvote 0
Ok this works for me. Copy and paste code below to replace the code you have in the Userform.

In addition you need to add the options C, D and E to the questions page and to add 3 options boxes rdC rdD and rdE to the userform. The easiest way is to copy option box B and paste. Then change the name to rdC and so on for the next two boxes.

Cheers

Code follows:

Private Sub button_next_Click()
''confirm there is a name
If TextBox1.Value = "" Then
MsgBox ("Please enter your name")
Exit Sub
End If
''confirm there is an answer
If rdA.Value = False And rdB.Value = False And rdC.Value = False And rdD.Value = False And rdE.Value = False Then
MsgBox ("Please select an answer")
Exit Sub
End If
''enter the name, question, and answer into results array
results(questionnumber - 1, 0) = QASurvey.TextBox1.Value
results(questionnumber - 1, 1) = questionnumber
If rda.Value = True Then
results(questionnumber - 1, 2) = "A" 'could put rda.caption
Else
results(questionnumber - 1, 2) = "B"
Else
If rdC.Value = True Then
results(questionnumber - 1, 2) = "C"
Else
If rdD.Value = True Then
results(questionnumber - 1, 2) = "D"
Else
If rdE.Value = True Then
results(questionnumber - 1, 2) = "E"
End If
End If
End If
End If
End If
''set the radio button to empty
rdA.Value = False
rdB.Value = False
rdC.Value = False
rdD.Value = False
rdE.Value = False
''populate the form with the next question
If questionnumber = UBound(info) + 1 Then
''stop
Call enterresults
MsgBox ("Thank You for completing the survey")
Unload QASurvey
Else
''populate next question
QASurvey.Label_question.Caption = info(questionnumber, 0)
QASurvey.rdA.Caption = info(questionnumber, 1)
QASurvey.rdB.Caption = info(questionnumber, 2)
QASurvey.rdC.Caption = info(questionnumber, 3)
QASurvey.rdD.Caption = info(questionnumber, 4)
QASurvey.rdE.Caption = info(questionnumber, 5)
End If
questionnumber = questionnumber + 1

End Sub
Sub enterresults()
Sheets("results").Select
Range("a2:e1000").ClearContents
''loop through results array
r = 2
For i = 0 To UBound(results)
Cells(r, 1).Value = results(i, 0)
Cells(r, 2).Value = results(i, 1)
Cells(r, 3).Value = results(i, 2)
Cells(r, 4).Value = results(i, 3)
Cells(r, 5).Value = results(i, 4)
r = r + 1
Next i
End Sub
Private Sub UserForm_Initialize()
Sheets("questions").Select
r = Range("a1").End(xlDown).Row - 1
ReDim info(r - 1, 5) 'redim 2 dimensional array
ReDim results(r - 1, 5) 'redim 2 dimensional array
'' fill a 2d array
r = 2
i = 0
Do Until Cells(r, 1).Value = ""
info(i, 0) = Cells(r, 1).Value
info(i, 1) = Cells(r, 2).Value
info(i, 2) = Cells(r, 3).Value
info(i, 3) = Cells(r, 4).Value
info(i, 4) = Cells(r, 5).Value
r = r + 1
i = i + 1
Loop
''populate the userform with data
QASurvey.Label_question.Caption = info(0, 0)
QASurvey.rda.Caption = info(0, 1)
QASurvey.rdb.Caption = info(0, 2)
QASurvey.rdC.Caption = info(0, 3)
QASurvey.rdD.Caption = info(0, 4)
QASurvey.rdE.Caption = info(0, 5)
questionnumber = 1
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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