Dim x, op$
Private Sub CommandButton1_Click()
Range("C9:I28").ClearContents
x = InputBox("Combien d'opérations ?")
If Not IsNumeric(x) Or x > 20 Then
x = ""
Exit Sub
End If
op = InputBox("Opérateur ?")
Select Case op
Case "+", "-", "*"
Case Else
Exit Sub
End Select
For i = 9 To x + 8
Cells(i, 3) = Int(Rnd() * 12 + 1)
Cells(i, 4) = op
Select Case op
Case "-"
Cells(i, 5) = Int(Rnd() * Cells(i, 3) + 1)
Case Else
Cells(i, 5) = Int(Rnd() * 12 + 1)
End Select
Cells(i, 6) = "="
Next
End Sub
Private Sub CommandButton2_Click()
If x = "" Or op = "" Then Exit Sub
For i = 9 To x + 8
y = Evaluate(Cells(i, 3) & op & Cells(i, 5)) = Cells(i, 7)
With Cells(i, 9)
If y Then
.Value = "EXACT"
.Font.ColorIndex = 10
Else
.Value = "FAUX"
.Font.ColorIndex = 3
End If
End With
Next
End Sub