Loop functions in VBA excel

Written by lysis
  • Share
  • Tweet
  • Share
  • Pin
  • Email
Loop functions in VBA excel
VBA is an Excel programming language. (number background image by kuhar from Fotolia.com)

Loops are statements that continue to execute until a condition is met. There are a few main loop functions used in VBA Excel programming: "while," "for" and "do while." Each loop function continues to execute, but the way the conditions are set up are different. The type of loop function used is determined by the programmer's necessities.


The while loop executes as long as the condition statement is equal to true. The while loop has a condition set at the beginning of the statement. For instance, the while loop is used in console applications for menu items. The while loop continues to execute until the user enters the proper value. Once the value is entered, the while loop discontinues and the coding execution jumps to the next statement located underneath the while loop block.

Do While

The do while loop is similar to the while loop. However, the difference is that the internal statements in the do while loop always execute once. The statements tell the application to do certain calculations until a condition is met. The condition is not evaluated until after the first loop statement is executed, so the do while loop is beneficial for applications that need the loop to run at least once. Do while statements are not commonly used in programming applications, but they are still an essential loop in Excel programming.


For loops are executed until a numerical value is reached. In the for loop, a variable is set at a value. The variable is incremented a number of times, which is also set in the for loop statement. The for loop is beneficial for programmers who know how many times the loop statements should be executed. For instance, a for loop can be used to cycle through a product list. Since the product list is a set number of values, programmers can set the iteration cycle based on the product count.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.