在 StackOverflow 上找不到這個問題,所以我很抱歉搜索不夠好......
我有以下代碼(簡化)
Sub Task_1()
"copy stuff from sheet2 to sheet1"
End Sub
Sub Task_2()
"Print sheet1"
End Sub
Sub Task_3()
"Do ordernumber 1"
End Sub
現在我想回圈這個。所以在sub Task_3之后,我想再次呼叫Task_1,直到某個單元格為空。我有以下內容,但不確定要在問號中添加什么。
Sub Start_orderprint()
Call Task_1
Call Task_2
Call Task_3
If Sheet1.Range("A4").Value <> Empty
Then ?????
Else
msgbox "Finished"
exit sub
End if
End sub
uj5u.com熱心網友回復:
ADo...Loop運行程式
Do...Loop statementUsing Do...Loop statements- 但要小心,因為這可能最終成為一個無限回圈(如果它永遠不會變成
Empty)。
Option Explicit
Sub Start_orderprint()
Do Until Sheet1.Range("A4").Value = Empty
' Or
'Do While Sheet1.Range("A4").Value <> Empty
Task_1
Task_2
Task_3
Loop
MsgBox "Finished"
End Sub
- 在前面的例子中,如果值是 initial
Empty,則永遠不會進入回圈。如果您想輸入一次,無論如何,您都必須使用以下內容:
Sub Start_orderprint()
Do
Task_1
Task_2
Task_3
Loop Until Sheet1.Range("A4").Value = Empty
' Or
'Loop While Sheet1.Range("A4").Value <> Empty
MsgBox "Finished"
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/348369.html
