Need help with Objective Type questions (Quiz)

JackiFrost

New Member
Joined
Jun 15, 2020
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
I am a DIYer and I am still learning VBA. Using different function found online, I am building a Quiz. It is working, but there is one thing I can't figure out. What I need is when a person picks his/her answer, user form must show(highlight in green) the correct answer, so that a person knows if he/she answered correctly, before clicking next button .
Person picks his answer, clicks NEXT button, user form will highlight the correct answer, wait for 2-3 seconds and proceed to next question.

Thank you in advance

The VBA Code:
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
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    214.6 KB · Views: 9

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Cross posted Need help with Objective Type questions (Quiz) - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,039
Members
449,063
Latest member
ak94

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