VBA案例陈述会运行多行代码吗?

时间:2012-07-23 02:16:00

标签: vba

我想知道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

1 个答案:

答案 0 :(得分:2)

当你的Select Case语句找到匹配的大小写时,它将运行所有代码,直到它成为新的CaseEnd 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