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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,215,506
Messages
6,125,189
Members
449,213
Latest member
Kirbito

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
Back
Top