Option Explicit
Sub New_Test() 'You get the idea here, I'm sure.
Dim Data As Range
Set Data = Range("B2:F16")
Data.Interior.ColorIndex = xlNone
Range("B18:F40,H4").ClearContents
End Sub
Sub Next_Test()
Dim i As Long
Dim j As Long
Dim k As Variant
Dim l AsLong
'this is where the focus of the code will return _
'if a number has already been called. See the "GOTO line1" _
'in the If statement below
line1:
i = Int((5 * Rnd) + 1) 'produces a random number between 1 & 5
j = Int((15 * Rnd) + 1) 'produces a random number between 1 & 15
Application.ScreenUpdating = False
Application.EnableEvents = False
'/ limit the number of questions asked in a test session &
'/ that number is set on sheet1 cell AT3
If Range("A4").Value = [AT3] Then '
MsgBox "Last Question", , "No More Q's!"
[J4:J7].ClearContents
[H4].ClearContents
Exit Sub
End If
'"i" & "j" are now a number between 1 & 5 & _
'1 & 15. So this line will offset from cell A1 _
'the number of rows = to "j" and the numbers of _
'columns = to "i" and select that cell.
Range("A1").Offset(j, i).Select
' sets "l" to the value of the cell that was just _
'selected in the Range("B2:F17")
l = ActiveCell.Value
Range("H4").Value = l
If ActiveCell.Interior.ColorIndex = 3 Then
GoTo line1
End If
MsgBox "Question is: " & vbCr & Range("I4")
With Range("J4").Resize(4, 1)
.Formula = "=VLOOKUP($H$4,$L$2:$AO$76,($AR$2)+ROW()-3,0)": .Value = .Value
End With
'If the selected cell is not red it turns it red here.
ActiveCell.Interior.ColorIndex = 3
If ActiveCell.Column = 2 Then
Range("B50").End(xlUp).Offset(1, 0) = ActiveCell.Value
ElseIf ActiveCell.Column = 3 Then
Range("C50").End(xlUp).Offset(1, 0) = ActiveCell.Value
ElseIf ActiveCell.Column = 4 Then
Range("D50").End(xlUp).Offset(1, 0) = ActiveCell.Value
ElseIf ActiveCell.Column = 5 Then
Range("E50").End(xlUp).Offset(1, 0) = ActiveCell.Value
ElseIf ActiveCell.Column = 6 Then
Range("F50").End(xlUp).Offset(1, 0) = ActiveCell.Value
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub