This should do the trick:
Sub test()
Dim Response%, Ans%
On Error Resume Next
Ans = Application.RandBetween(1, 100)
TryAgain:
Response = CInt(InputBox("Pick a number between 1 and 100"))
If Response > 0 Or Response < 100 Then
If Ans = Response Then
MsgBox "Correct Answer", vbExclamation
Ans = 0
ElseIf Ans < Response Then
If MsgBox("Try a lower number", vbExclamation + vbOKCancel) = vbOK Then GoTo TryAgain
ElseIf Ans > Response Then
If MsgBox("Try a higher number", vbExclamation + vbOKCancel) = vbOK Then GoTo TryAgain
End If
End If
End Sub
You can extend this to using a userform instead of an input box, etc.
abousetta
Bookmarks