- VBA 教程
- VBA - 首頁
- VBA - 概述
- VBA - Excel 宏
- VBA - Excel 術語
- VBA - 宏註釋
- VBA - 訊息框
- VBA - 輸入框
- VBA - 變數
- VBA - 常量
- VBA - 運算子
- VBA - 決策
- VBA - 迴圈
- VBA - 字串
- VBA - 日期和時間
- VBA - 陣列
- VBA - 函式
- VBA - 子過程
- VBA - 事件
- VBA - 錯誤處理
- VBA - Excel 物件
- VBA - 文字檔案
- VBA - 程式設計圖表
- VBA - 使用者窗體
- VBA 有用資源
- VBA - 快速指南
- VBA - 有用資源
- VBA - 討論
VBA - While Wend 迴圈
在 While...Wend 迴圈中,如果條件為真,則將一直執行所有語句,直到遇到關鍵詞 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
vba_loops.htm
廣告
