Do While Loop MS Excel

The use of 'do while' in Excel macros helps us to automate the manipulations that we wish to do with the data in excel worksheet cells. The main points to remember when using a 'do while' loop is:

  • Initialize the starting point of the loop
  • Define the conditions under which the loop will run and stop
  • Perform the loop
  • Inside the loop you can define other conditions, let's say, do something 'if'
  • Go to the next row or data
  • Terminate the loop
In the  training video we start at row 2. From the salary in cell B2 we calculate the benefits at 40% of salary in cell C2. Now we add the salary and the benefits to calculate the total package. All the calculations are automated using the 'do while' loop  and accessing the cells using 'cells(row no, column no)'.

If we forget to define any of these steps either the loop will not execute correctly or get into an infinite loop. This is what happens when we say the computer has 'hung'. Pre the  'escape =esc' key on the top left of the keyboard to stop the loop and then correct any errors.

Watch the video below to learn more about the looping process using Excel VBA::

Watch the video on youtube