Код:
Option Explicit
Sub Sample()
Dim strName As String
Dim i As Integer
Dim x1 As Integer
Dim x2 As Integer
Dim strAnswer As String
With ThisWorkbook.Sheets.Item(1)
.Range(.Cells.Item(1, 1), .Cells.Item(14, 4)).Clear
strName = InputBox("Enter your name:", "Enter your name")
With .Cells
.Item(1, 1).Value = strName
Randomize Timer
i = 1
Do
x1 = Int(9 * Rnd + 1)
x2 = Int(9 * Rnd + 1)
strAnswer = Trim(InputBox(x1 & " x " & x2 & " = ?", "Question #" & CStr(i)))
If IsNumeric(strAnswer) Then
.Item(i + 1, 1).Value = x1
.Item(i + 1, 2).Value = x2
.Item(i + 1, 3).Value = x1 * x2
.Item(i + 1, 4).Value = CInt(strAnswer)
If x1 * x2 = CInt(strAnswer) Then
.Item(i + 1, 4).Interior.ColorIndex = 4
Else
.Item(i + 1, 4).Interior.ColorIndex = 3
End If
i = i + 1
Else
If MsgBox("Need only digits." & vbCrLf & vbCrLf & "Try again?", vbYesNo + vbExclamation, "Need only digits") = vbNo Then
MsgBox "Test failed!", vbOKOnly + vbCritical, "Test failed"
Exit Do
End If
End If
Loop While i <= 12
.Item(i + 1, 1).Value = "Result: bla-bla-bla."
End With
End With
End Sub