Learn VBA Part 23 – Use Nested FOR NEXT Loop in VBA Hindi
The For Next Loop can be Nested also as in you can have a loop within a loop as we learnt earlier that The VBA Excel FOR NEXT statement is used to create a FOR loop so that you can execute VBA code a fixed number of times., in this video you will learn how to use Nested For Loop in VBA Hindi.
This VBA example shows that you can use Nested For Next Loop to create a multiplication table with vba macro.
To learn more about Excel Macros please visit http://www.myelesson.org/vba-training-videos/
When a For…Next loop starts, Visual Basic evaluates start, end, and step. Visual Basic evaluates these values only at this time and then assigns startto counter. Before the statement block runs, Visual Basic compares counter to end. If counter is already larger than the end value (or smaller if step is negative), the For loop ends and control passes to the statement that follows the Next statement. Otherwise, the statement block runs.
Each time Visual Basic encounters the Next statement, it increments counter by step and returns to the For statement. Again it compares counter toend, and again it either runs the block or exits the loop, depending on the result. This process continues until counter passes end or an Exit Forstatement is encountered.
The loop doesn’t stop until counter has passed end. If counter is equal to end, the loop continues. The comparison that determines whether to run the block is counter <= end if step is positive and counter >= end if step is negative.
If you change the value of counter while inside a loop, your code might be more difficult to read and debug. Changing the value of start, end, orstep doesn’t affect the iteration values that were determined when the loop was first entered.
If you nest loops, the compiler signals an error if it encounters the Next statement of an outer nesting level before the Next statement of an inner level. However, the compiler can detect this overlapping error only if you specify counter in every Next statement