Vba-while-wend-loop

提供:Dev Guides
移動先:案内検索

VBA-While Wendループ

*While…Wend* ループでは、条件がTrueの場合、 *Wend* キーワードが見つかるまですべてのステートメントが実行されます。

条件が偽の場合、ループは終了し、コントロールは Wend キーワードの次のステートメントにジャンプします。

構文

VBAの While..Wend ループの構文は次のとおりです。

While condition(s)
   [statements 1]
   [statements 2]
   ...
   [statements n]
Wend

流れ図

ループアーキテクチャー

Private Sub Constant_demo_Click()
   Dim Counter :  Counter = 10

   While Counter < 15     ' Test value of Counter.
      Counter = Counter + 1   ' Increment Counter.
      msgbox "The Current Value of the Counter is : " & Counter
   Wend   ' While loop exits if Counter Value becomes 15.
End Sub

上記のコードが実行されると、メッセージボックスに次のコードが出力されます。

The Current Value of the Counter is : 11

The Current Value of the Counter is : 12

The Current Value of the Counter is : 13

The Current Value of the Counter is : 14

The Current Value of the Counter is : 15