Sub Quiz()
Dim Question As Integer, Answer As String, Num As Integer, LastRow As Long, Correct As Integer
'copy questions from database to test area
Sheet2.Range("H1:I20").Value = Sheet2.Range("Q1:R20").Value
Sheet2.Range("M2:N20").ClearContents
For Question = 1 To 10
'Transfer one random question
LastRow = Sheet2.Cells(Rows.Count, "H").End(xlUp).Row
Num = WorksheetFunction.RandBetween(2, LastRow)
'Take random question from the bank (prevents repeat questions)
Sheet2.Range("H" & Num & ":I" & Num).Select
Selection.Cut
'Add it to the questions asked list
LastRow = Cells(Rows.Count, "M").End(xlUp).Row
Sheet2.Range("M" & LastRow + 1).Select
ActiveSheet.Paste
'delete the cells the question came from
Sheet2.Range("H" & Num & ":I" & Num).Delete Shift:=xlUp
'Now ask the question
Retry:
Answer = InputBox(Sheet2.Range("M" & LastRow + 1).Value, "Question " & Question, "")
If UCase(Answer) = "" Then GoTo Retry 'No answer given
If UCase(Answer) = UCase(Sheet2.Range("N" & LastRow + 1).Value) Then 'Correct answer
Correct = Correct + 1
Else
End If
MsgBox Correct & " out of " & Question
Sheet2.Range("O" & LastRow + 1).Value = Answer 'Store the given answer
Next Question
End Sub
everything is great. I had a problem generating question then I suddenly noticed that you've referenced a wrong sheet. Thank you so much again. I need to custom fit this to my project.
Bookmarks