Search
Close this search box.

VBA – Loops


You might need to run a block of code multiple times in each scenario. Statements always run in order: The first statement in a function is executed first, followed by the second, and so on.

Different control structures offered by programming languages enable more complex execution routes.

We can run a statement or set of statements repeatedly by using a loop statement. The general format of a loop statement in Visual Basic.

VBA provides the following types of loops to handle looping requirements.

For loop:- summarises the code that controls the loop variable and repeatedly runs a series of statements.

For each loop:- This is repeated for every element in a group and is carried out if there is at least one element in the group.

While wend loop:- This runs the loop body after testing the condition.

Do while loop:- When the condition is true, the “do while” statements will be carried out. It is necessary to repeat the loop until the condition is false. 

Do until loop:- The “do Until” statements will run as long as the condition is false. The loop must be repeated until the requirement is met.