VBA_Excel_教程:分枝循环结构

时间:2022-02-26 06:49:14
Sub 分枝()
tmp = Cells(, ).Value '变量不用定义,当前写代码的Sheet
Debug.Print tmp
If tmp = "" Then
Debug.Print "A" 'ElseIf是连着的
ElseIf tmp = "" Then
Debug.Print "B"
Else
Debug.Print "C"
End If
End Sub
Sub 分枝()
tmp = Cells(, ).Value '变量不用定义,当前写代码的Sheet Select Case tmp
Case
Debug.Print "A"
Case
Debug.Print "B"
Case
Debug.Print "C"
Case
Debug.Print "D"
Case Else
Debug.Print "Z"
End Select
End Sub
Sub For循环()
'i不用定义
For i = To
Debug.Print i
Next
End Sub
Sub doWhileLoop()
i =
Do While i < '摸着石头过河
Debug.Print i i = i +
Loop
Debug.Print "------------------------------"
i =
Do
Debug.Print i i = i +
Loop While i < '先下河再找石头
Debug.Print "------------------------------"
i =
Do Until i > '摸到石头就走
Debug.Print i i = i +
Loop
Debug.Print "------------------------------"
i =
Do
Debug.Print i i = i +
Loop Until i > '走到摸不到石头
End Sub
Sub while循环()
i =
While i <
Debug.Print i If i = Then
i = '利用While的破坏条件退出循环 '
End If
i = i +
Wend
End Sub