98.8% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel Training and help » Loop and Locals window
Loop and Locals window
Resolved · Low Priority · Version 365
Qasim has attended:
Excel VBA Intermediate course
Loop and Locals window
Initially in MyModule, we set x = 1 to 5 and y = 1 to 10. When we press F8 to step through the code, it shows:
x = 1, y = 1
x = 1, y = 2....
eventually we get:
x = 1, y = 11 even though y ends at 10.
Any idea why this is?
It also occurs at the end of the run and shows x = 6, y = 11.
RE: Loop and Locals window
Hi Qasim,
Thank you for the forum question.
Yes if you use a For Next loop For x=1 to 10, it will count to 11.
The logic is that you type the line For x=1 to 10 above the code you want to loop trough. When you step the code (F8) you can see in the Locals Window, that you add 1 to x every time you reach the line Next x. When you have 10 in x you still want to run the lines
under the line For x=1 to 10 one more time (it will be the tenth time). When you get to the line Next x you will get x=11 and the loop will stop.
I hope this makes sense.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Training information:
See also:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Hiding and unhiding rows using the keyboardCTRL + 9 hides your columns and CTRL + SHIFT + ( unhides them although you would need to highlight the row letters either side as per normal |