Excel VBA - If Statement Problem

  • Thread starter Thread starter ajlove20
  • Start date Start date
A

ajlove20

Hi,

I have this code:

Sub Area()

Dim x, y, k, j
x = InputBox("Please enter the starting number for the X Value"
"STARTING POINT", "", 100, 1)
y = InputBox("Please enter the last number for the X Value", "FINISHIN
POINT", "", 100, 1)

If Not IsNumeric(x) Then
OkOnly = MsgBox("The STARTING NUMBER MUST BE NUMERIC", vbOKOnly
vbCritical, "ERROR")
x = InputBox("Please enter the starting number for the X Value"
"STARTING POINT", "", 100, 1)
Else
If x > 200 Then
OkOnly = MsgBox("The STARTING NUMBER CANNOT BE GREATER THAN 200"
vbOKOnly + vbCritical, "ERROR")
x = InputBox("Please enter the starting number for the X Value"
"STARTING POINT", "", 100, 1)
Else
If x < -200 Then
OkOnly = MsgBox("The STARTING NUMBER CANNOT BE LESS THA
(-200)", vbOKOnly + vbCritical, "ERROR")
x = InputBox("Please enter the starting number for the
Value", "STARTING POINT", "", 100, 1)
Else
End If
End If
End If

k = ((y - x) / 100)
Range("O11").Value = k
[O9] = "Distance in Between 2 X Values"
[M9] = "User's X Value"
[M10] = x
[M11] = k + x
[M12:M110].FormulaR1C1 = "=R[-1]C+R11C15"

UserForm1.Show

End Sub



When I put in a number for x and I get an error, I want it to ask me t
put in a different number and check for the error. What I got onl
asks me for the another x and doesn't check for the error. I tried t
use Call Area, but that gave me output for every number entered eve
the ones with the error. How would I go about getting this program t
function properly?

Thanks in advance.

a
 
Maybe this will give you one idea
Sub ifnotnum()
start:
x = InputBox("enter number")
If Not IsNumeric(x) Then MsgBox "HI": GoTo start
'more stuff
End Sub
 
Hi,

Thank you. Your idea worked perfectly. I appreciate you taking th
time to help me.

Thanks again.

a
 
Back
Top