I just started learning VBA and I am trying to ask user to input
a number between 1 and 1000, and I wrote the following code:
----------------------------------------------------------------------------------------
Sub Simu()
Dim Iter As Variant
Dim Msg As String
Dim Ans As Integer
EnterAgain:
On Error GoTo BadEntry
Iter = InputBox("How many iterations do you want? Please enter a number between 1 and 1000", Simulation)
If Iter = "" Then Exit Sub
If (Iter < 1 Or Iter > 1000) Then GoTo BadEntry
Call Reset
For i = 1 To Iter
Application.Calculate
Next i
Exit Sub
BadEntry:
Msg = "Your have entered an invalid number, you want to enter again?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbYes Then Resume EnterAgain
End Sub
-------------------------------------------------------------------------------------------------------------
Everything works fine except that the yes/no msgbox will always pop up twice
before the inputbox pops up. That means Excel will ask twice if the user want to enter
a number again...Can anyone help?
Bookmarks