我想知道VBA case语句是否会运行多行代码:
Const HARD = 30
Select Case Hardness
Case "Hard"
If PenetrationRate.Cells(i, 1) >= Hard Then
Total = Total + Metres.Cells(i, 1)
DoEvents
End If
Case "Soft"
If PenetrationRate.Cells(i, 1) < Hard Then
Total = Total + Metres.Cells(i, 1)
DoEvents
End If
End Select
答案 0 :(得分:2)
是
当你的Select Case
语句找到匹配的大小写时,它将运行所有代码,直到它成为新的Case
或End Select
..你可以嵌套循环或任何其他类型的每种情况下的编码结构。
过于清楚,对于Hardness = "Hard"
案例语句运行时的代码:
If PenetrationRate.Cells(i, 1) >= Hard Then
Total = Total + Metres.Cells(i, 1)
DoEvents
End If
当Hardness = "Soft"
case语句运行时:
If PenetrationRate.Cells(i, 1) < Hard Then
Total = Total + Metres.Cells(i, 1)
DoEvents
End If