The code below is VBA for Excel. I am using the Visual Basic editor that comes with Excel 2007.
Dim counter As Integer
counter = 1
While counter < 20
counter = counter + 1
end while '<- the compiler is complaining about this statement
The code doesn't compile. Above the code I have only declarations. According to MSDN this should work but it doesn't. What has happened?
VBA is not VB/VB.NET
The correct reference to use is Do..Loop Statement (VBA). Also see the article Excel VBA For, Do While, and Do Until. One way to write this is:
Do While counter < 20
counter = counter + 1
Loop
(But a For..Next might be more appropriate here.)
Happy coding.
Source: Stackoverflow.com