Do Until with multiple condidtions

alexaronson

Active Member
Joined
Sep 30, 2005
Messages
314
Hello

I am writing some code that ask a user to input two variabls via an InputBox.

In order for the down stream code to work there are 3 conditions that have to be met.
1) startValue > 0
2) endValue < 100
3) startValue < endValue

I am trying to use a Do Until function, but I cannot seem to figure out how to get it reprompt the user until all 3 conditions are met.

Here is what I have so far.
Code:
Dim startValue as Integer, endValue as Integer

startValue = InputBox(Prompt:="Please enter the least number of days to compute an average with greater than 0.")
endValue = InputBox(Prompt:="Please enter the most number of days to compute an average with.  100 is the max")

Do Until startValue < endValue
    startValue = InputBox(Prompt:="Please enter the least number of days to compute an average with must be less than the most number of days, please enter agian.")
    endValue = InputBox(Prompt:="Please enter the most number of days to compute an average with must be more than the least number of days.  100 is the max")
Loop

Thanks for any help you can give!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try

Code:
Do Until startValue < endValue And startValue > 0 And endValue < 100
 
Upvote 0
Why don't you try a useform rather than inputboxes?

It could have textboxes for the 2 values and a command button to continue with the code.

That command button could be disabled until the criteria are fulfilled.
 
Upvote 0
Thanks VoG and phxsportz. The line changed worked.

Norie,

How do I create a userform? I have never heard of that before. Also what is the advantage of the userform over the Do Until statement?

Thanks for the education and help to all!
 
Upvote 0
Well to create a userform goto the VBE (ALT+F11) and then Insert>Userform.

You should now see a blank userform and also a Toolbox.

From the toolbox you can add various controls to the userform. eg textboxes, command buttons etc.

I don't know if there is any advantage per se of using a userform but it might allow you more control over what's happening.

You could even restrict the values the user can enter by using a listbox or combobox.:)
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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