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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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