本文介绍了VBA替换嵌套的if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使它更有效?我觉得有点丑.我想验证是否存在下一个甲板",如果有,对其执行一些,直到deck8

Is there a way to make this more efficient? I find it a bit ugly.I want to verity if there is a next "deck", if so, execute some for it, until deck8

这是我的代码:

         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

推荐答案

使用案例声明

Select Case deckNum

case 0
    'execute code for deck 0
case 1
    'execute code for deck 1
case 2
    'execute code for deck 2
case 3
    'execute code for deck 3
End Select

这是Office VBA参考 http://msdn.microsoft. com/en-us/library/office/gg278454.aspx

Here is an office VBA reference http://msdn.microsoft.com/en-us/library/office/gg278454.aspx

这篇关于VBA替换嵌套的if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 06:02