VBA: Selecting values in an interval by using the InputBox

mathgirl09

New Member
Joined
Jun 4, 2015
Messages
10
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
Joined
Oct 27, 2005
Messages
21,651
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
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
 
Upvote 0

Forum statistics

Threads
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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Top