A Do/Loop loop is used for repeating something for infinity, or until a condition is true. It loops certain code so that depending on the conditions, when it reaches the end of the loop, it will restart the loop and repeat the code.
Here is the layout for the loop.
Do Code to loop goes here Loop
The Do function defines the start of the loop. Anything in between the Do and the Loop will get repeated. Here's an example of looping a message box until they click no, using a variable with the name "CheckMessage".
Do Until CheckMessage = vbNo CheckMessage = MsgBox("Click no to close this. Click yes for it to come again.", vbYesNo) Loop
That uses the "Until" condition - it says that it will loop the code until CheckMessage equals vbNo (They click no). Here's a loop using the While function as a conditional statement, using a variable with the name "CheckMessage".
Do While CheckMessage = "False" CheckMessage = MsgBox("Click no to close this. Click yes for it to come again.", vbYesNo) If CheckMessage = vbYes Then CheckMessage = "True" Else CheckMessage = "False" End If Loop
Your code will repeat for infinity until you shut it down with task manager or some such thing if you just leave it as the next example, so be careful:
Do MsgBox "Haha" Loop
You want to avoid that sort of thing unless you want to be annoying. However, one way out of a loop like that would be to use an Exit Do function. Here's an example:
Do If MsgBox("Click no to close this.", vbYesNo) = vbNo Then Exit Do End If Loop
The Exit Do will bring the code to the end of the loop and continue with the next line after "Loop".