【发布时间】:2013-10-27 15:20:18
【问题描述】:
有没有办法提高效率?我觉得有点丑。 我想验证是否有下一个“甲板”,如果有,执行一些,直到甲板8
这是我的代码:
If deckNum > 0 Then
'Execute code for deck 1
If deckNum > 1 Then
'Execute code for deck 2
If deckNum > 2 Then
'Execute code for deck 3
If deckNum > 3 Then
'Execute code for deck 4
If deckNum > 4 Then
'Execute code for deck 5
If deckNum > 5 Then
'Execute code for deck 6
If deckNum > 6 Then
'Execute code for deck 7
If deckNum > 7 Then
'Execute code for deck 8
End If
End If
End If
End If
End If
End If
End If
End If
【问题讨论】:
-
'Execute code for deck 1是 1 行代码还是多行代码?你的 if 也不应该反过来吗?即从 7 到 0 而不是 0 到 7? -
另外,请注意,是基于甲板编号的代码变量(即甲板 2 执行 x 2 次,甲板 3 执行 3 次等)。任何有模式的东西,我想我都懂了。
标签: excel if-statement nested performance vba