How to switch between two Do Until Loop procedures

StaffordStag

New Member
Joined
Oct 1, 2023
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Can anyone help me please. I am writing VBA code which, if I can get it to work as I want it to, allows the user to select one of two ‘Do Until, Loop’ statements. Allow me to explain. My program outputs numbers printing them on a Worksheet. I wish to give the user the choice of either (A) limiting the output to a range of numbers, e.g. 100 to 10,000, or (B) allow the output of numbers to run without check until the user intervenes and halts the process. The lines of code are as follows:

  • Do Until y = EndNumber …procedure….. y = y + 1, Loop
  • Do Until y > StartNumber \ 10 + y …procedure….. y = y + 1, Loop
Having done some online searching I think I need to invoke the Evaluate function. I have made several attempts but have failed to achieve my objective. Is there anyone out there who can tell me exactly how to code for this feature.

Just so you know I am a novice when it comes to coding so if my terminology is questionable, please excuse me.

I am using Excel 2019 and VBA 7.1. I am running it on Windows 10, 64-Bit.

In anticipation of your help thank you.
 
Hello

With StartNumber > 0, does this expression:
y <= StartNumber / 10 + y
always evaluate to TRUE?
So,
VBA Code:
Do While y <= StartNumber / 10 + y
...
y = y + 1
Loop
Is it certain that the loop is infinite?

Agreed. I thought the same and urged caution with this kind of loop.
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Did you name your Sub and your Module with the same name? If so, try changing one of them. I ran the code shown above and it works fine if included in a Module or a Sheet. If you can simplify your code and paste it here, I will try to take a look.
Hi NateSC. I have been out of the country for a week plus and have only just picked up on my coding again. Thank you for your guidance once again. We your help I have successfully the program to work as I want it to but there still more I must do before it is a finished piece of work.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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