# VBA: Selecting values in an interval by using the InputBox

#### mathgirl09

##### New Member
Hi!
I'd like to know if there's a way to create an InputBox to ask for 2 values but these values must range from (1 to 20) by excluding the interval (5 to 15) inclusively. If the values are in the interval (5 to 15), a MsgBox must appear and tell to retry :
Code:
``MsgBox("The value entered is in the interval (5,15). Try again.")``

Also value#1 must be smaller than value#2, if not a MsgBox will appear again:
Code:
``MsgBox ("Value#1 is larger than value#2. Try again.")``

Then, the end result will be =value1/value2.

Thank you!

Last edited:

### Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},\$Z\$1:\$Z\$99,\$Y\$1:\$Y\$99),2,False) to lookup Y values to left of Z values.

#### Michael M

##### Well-known Member
I'm guessing there is way more to this, but here goes

Code:
``````Sub MM1()
str1 = Application.InputBox("Enter a number below 5 and above zero", "Numbers required", Type:=1)
Str2 = Application.InputBox("Enter a number above 15 and below 20", "Numbers required", Type:=1)
If str1 > Str2 Then
MsgBox ("Value#1 is larger than value#2. Try again.")
Exit Sub
End If
If str1 > 4 Or Str2 < 16 Then
MsgBox ("The value entered is in the interval (5,15). Try again.")
Exit Sub
End If

End Sub``````

#### mathgirl09

##### New Member
Thank you! It helped me a lot!

Replies
10
Views
209
Replies
1
Views
306
Replies
5
Views
271
Replies
5
Views
209
Replies
1
Views
331

1,196,021
Messages
6,012,904
Members
441,740
Latest member
Latrs

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back