Put the code below in a standard code module.
Delete your old cmdStartQuiz and restart procedures.
Assign cmdNextQ to each Next Question button.
Delete or comment out all the event procedures in the Q sheets and Results sheet code modules.
Public interval As Date
Public bNextQ As Boolean
Sub QTimer() 'For Q1-Q20
Dim NextSheet As Integer
Range("B1") = Range("B1") - TimeValue("00:00:01")
If Range("B1").Value <= 0 Or bNextQ Then 'next Q-sheet when time out or button clicked
If Not bNextQ Then MsgBox "Out of Time", , ""
bNextQ = False
If ActiveSheet.Name = "Q20" Then
Sheets("Result").Visible = True
Sheets("Result").Select
Sheets("Q20").Visible = xlSheetVeryHidden
Exit Sub
ElseIf ActiveSheet.Name Like "Q*" Then
NextSheet = Mid(ActiveSheet.Name, 2) + 1 'next Q sheet number
Sheets("Q" & NextSheet).Visible = True
Sheets("Q" & NextSheet).Select
Range("B1").Value = ("00:00:20")
Sheets("Q" & NextSheet - 1).Visible = xlSheetVeryHidden 'Hide previous Q sheet
End If
End If
interval = Now + TimeValue("00:00:01")
If ActiveSheet.Name Like "Q*" Then Application.OnTime interval, "QTimer"
End Sub
Sub QTimer_Stop()
On Error Resume Next
Application.OnTime interval, "QTimer", Schedule:=False
End Sub
Sub cmdStartQuiz()
Sheets("Q1").Visible = xlSheetVisible
Sheets("Q1").Select
Range("B1").Value = ("00:00:20")
QTimer
Sheets("Main").Visible = False
End Sub
Sub restart()
'
' restart Macro
'
Dim i As Integer
With Sheets("Main")
.Visible = True
.Range("F11:K13").ClearContents
.Select
End With
Sheets("Records").Visible = xlSheetVeryHidden
Sheets("Result").Visible = xlSheetVeryHidden
Sheets("ForEmail").Range("B5:B24").ClearContents
Sheets("ForEmail").Visible = xlSheetVeryHidden
For i = 1 To 20
With Sheets("Q" & i)
.Range("B5").ClearContents
.Visible = xlSheetVeryHidden
End With
Next i
End Sub
Sub cmdNextQ()
QTimer_Stop
bNextQ = True
QTimer
End Sub
Bookmarks