Introduction: Create Objective Type Questions in Excel
I used this kind of question paper to create sample questions for ISTQB sample papers for the candidates to test their aptitude. The same template can be used to make many other question papers in the same way. You just have to use the same template and add your own set of questions. The questions are objective type with 4 options. I got the idea from Kaun banega carorepati (an Indian version of Who wants to be a millionaire)
Attachments
Step 1: Creating the Worksheets
Open Excel. Make sure you save the file as .xls (office 2003 format) as in the office 2007 and above formats the macros is not saved properly.
Create 2 worksheets named "Querstions" and "Testing Questions"
In the Questions worksheet create or copy the questions that you want to be asked, with the correct answers ofcourse.
In the cell H1 put the formula =COUNTA(G:G) (this will keep track of the questions marked to be asked)
In the cell I1 put the formula =COUNTA(A:A) (this will keep track of total number of questions)
In the Testing Questions worksheet create a button that will launch the question form.
Create 2 worksheets named "Querstions" and "Testing Questions"
In the Questions worksheet create or copy the questions that you want to be asked, with the correct answers ofcourse.
In the cell H1 put the formula =COUNTA(G:G) (this will keep track of the questions marked to be asked)
In the cell I1 put the formula =COUNTA(A:A) (this will keep track of total number of questions)
In the Testing Questions worksheet create a button that will launch the question form.
Step 2: Creating User Form
Open VBA and create a user form.
Put 7 controls as shown in the image.
Create proper names for the controls (final file is attached)
Put 7 controls as shown in the image.
Create proper names for the controls (final file is attached)
Step 3: Write the Code
Create a macro for the Button on the worksheet
*************************
Sub Button1_Click()
Randomize
totalq = CInt(Range("Questions!I1").Text)
For i = 1 To totalq
Range("Questions!G" & i).FormulaR1C1 = ""
Next
While (Range("Questions!H1").Text <> 10)
i = Round(1 + ((totalq - 1) * Rnd()), 0)
Range("Questions!G" & i).FormulaR1C1 = "A"
Wend
QForm.Show
End Sub
*************************
Also create the VBA code for the form to work
*************************
Dim counter, ans, qcounter
Private Sub Answer1_Click()
Button.Enabled = True
End Sub
Private Sub Answer2_Click()
Button.Enabled = True
End Sub
Private Sub Answer3_Click()
Button.Enabled = True
End Sub
Private Sub Answer4_Click()
Button.Enabled = True
End Sub
Private Sub Button_Click()
If (Answer1.Value = True) Then
ans = 1
ElseIf (Answer2.Value = True) Then
ans = 2
ElseIf (Answer3.Value = True) Then
ans = 3
ElseIf (Answer4.Value = True) Then
ans = 4
End If
ansacc = CInt(Range("Questions!F" & counter).Text)
If (ansacc = ans) Then
status.Width = status.Width + 30
End If
Answer1.Value = False
Answer2.Value = False
Answer3.Value = False
Answer4.Value = False
counter = counter + 1
qcounter = qcounter + 1
If qcounter <= 10 Then
While (Range("Questions!G" & counter).Text <> "A")
counter = counter + 1
Wend
Question.Caption = Range("Questions!A" & counter).Text
Answer1.Caption = Range("Questions!B" & counter).Text
Answer2.Caption = Range("Questions!C" & counter).Text
Answer3.Caption = Range("Questions!D" & counter).Text
Answer4.Caption = Range("Questions!E" & counter).Text
End If
Button.Enabled = False
If qcounter = 11 Then
MsgBox ("Your score is " & 10 * status.Width / 30 & "%")
QForm.Hide
End If
End Sub
Private Sub UserForm_Activate()
counter = 1
Answer1.Value = False
Answer2.Value = False
Answer3.Value = False
Answer4.Value = False
status.Width = 0
Button.Enabled = False
ans = 0
While (Range("Questions!G" & counter).Text <> "A")
counter = counter + 1
Wend
Question.Caption = Range("Questions!A" & counter).Text
Answer1.Caption = Range("Questions!B" & counter).Text
Answer2.Caption = Range("Questions!C" & counter).Text
Answer3.Caption = Range("Questions!D" & counter).Text
Answer4.Caption = Range("Questions!E" & counter).Text
qcounter = 1
End Sub
*************************
*************************
Sub Button1_Click()
Randomize
totalq = CInt(Range("Questions!I1").Text)
For i = 1 To totalq
Range("Questions!G" & i).FormulaR1C1 = ""
Next
While (Range("Questions!H1").Text <> 10)
i = Round(1 + ((totalq - 1) * Rnd()), 0)
Range("Questions!G" & i).FormulaR1C1 = "A"
Wend
QForm.Show
End Sub
*************************
Also create the VBA code for the form to work
*************************
Dim counter, ans, qcounter
Private Sub Answer1_Click()
Button.Enabled = True
End Sub
Private Sub Answer2_Click()
Button.Enabled = True
End Sub
Private Sub Answer3_Click()
Button.Enabled = True
End Sub
Private Sub Answer4_Click()
Button.Enabled = True
End Sub
Private Sub Button_Click()
If (Answer1.Value = True) Then
ans = 1
ElseIf (Answer2.Value = True) Then
ans = 2
ElseIf (Answer3.Value = True) Then
ans = 3
ElseIf (Answer4.Value = True) Then
ans = 4
End If
ansacc = CInt(Range("Questions!F" & counter).Text)
If (ansacc = ans) Then
status.Width = status.Width + 30
End If
Answer1.Value = False
Answer2.Value = False
Answer3.Value = False
Answer4.Value = False
counter = counter + 1
qcounter = qcounter + 1
If qcounter <= 10 Then
While (Range("Questions!G" & counter).Text <> "A")
counter = counter + 1
Wend
Question.Caption = Range("Questions!A" & counter).Text
Answer1.Caption = Range("Questions!B" & counter).Text
Answer2.Caption = Range("Questions!C" & counter).Text
Answer3.Caption = Range("Questions!D" & counter).Text
Answer4.Caption = Range("Questions!E" & counter).Text
End If
Button.Enabled = False
If qcounter = 11 Then
MsgBox ("Your score is " & 10 * status.Width / 30 & "%")
QForm.Hide
End If
End Sub
Private Sub UserForm_Activate()
counter = 1
Answer1.Value = False
Answer2.Value = False
Answer3.Value = False
Answer4.Value = False
status.Width = 0
Button.Enabled = False
ans = 0
While (Range("Questions!G" & counter).Text <> "A")
counter = counter + 1
Wend
Question.Caption = Range("Questions!A" & counter).Text
Answer1.Caption = Range("Questions!B" & counter).Text
Answer2.Caption = Range("Questions!C" & counter).Text
Answer3.Caption = Range("Questions!D" & counter).Text
Answer4.Caption = Range("Questions!E" & counter).Text
qcounter = 1
End Sub
*************************
Step 4: Execute the Code
Click the start test button. The user form should open and the options with the questions should be populated. If it does not open, that means your macro settings are not set. Kindly google for the same.
Step 5: How Does It Work
1. First 10 questions are marked at random.
2. The user form is opened and the first question is put to the user.
3. When the user selects an answer the Next button is enabled.
4. When the next button is clicked the code compares the right answer with the user's answer and if it is OK the score bar is increased.
5. This happens till all the 10 marked questions have been answered.
2. The user form is opened and the first question is put to the user.
3. When the user selects an answer the Next button is enabled.
4. When the next button is clicked the code compares the right answer with the user's answer and if it is OK the score bar is increased.
5. This happens till all the 10 marked questions have been answered.
Step 6: Secure the Questions
Now the questions have to be hidden from the user, so that he/she should not be able to see the answers.
For doing this, In the VBA window mark its visibility as VeryHidden.
You can also protect the sheet by password protecting it etc. But that's up to you.
The attached workbook does not have these things incorporated.
For doing this, In the VBA window mark its visibility as VeryHidden.
You can also protect the sheet by password protecting it etc. But that's up to you.
The attached workbook does not have these things incorporated.