“While .. End While” doesn't work in VBA?

前端 未结 2 390
北荒
北荒 2020-12-16 09:56

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
           


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-16 10:30

    While constructs are terminated not with an End While but with a Wend.

    While counter < 20
        counter = counter + 1
    Wend
    

    Note that this information is readily available in the documentation; just press F1. The page you link to deals with Visual Basic .NET, not VBA. While (no pun intended) there is some degree of overlap in syntax between VBA and VB.NET, one can't just assume that the documentation for the one can be applied directly to the other.

    Also in the VBA help file:

    Tip The Do...Loop statement provides a more structured and flexible way to perform looping.

提交回复
热议问题