Excel VBA如何使用索引当我们有更多的如果然后其他function

我有一个VBA代码,多于50行If Then ElseIf函数。 当我运行macros,它将满足一个“如果”条件。 如果数据符合第50条Elseif条件,那么如果条件满足,则macros将进入49。 我知道,一个符合条件的基本价值。 因为我能够find符合条件的价值,所以如果条件,我可以直接跳到那个特定的? 任何帮助将非常感激

If A=10 and B=39 then Do Something.... Elseif A=11 and B=30 and C=56 then Do Something.... Elseif A=13 and B=35 and C=60 then Do Something.... ... etc 

因为我知道A = 13,我可以直接跳到

 Elseif A=13 and B=35 and C=60 then 

没有通过前两个如果条件?

对你的问题 – 你可以优先考虑49. ElseIf条件 – 没有

但是如果你想在debugging中更快地做到这一点,你可以把它放在数字1或2。 喜欢这个:

 Public Sub TestMe() Dim a As Long a = 5 If a < 6 Then Debug.Print "The most popular" ElseIf a = 5 Then Debug.Print "The 2. most popular" ElseIf a > 2 Then Debug.Print "The 3. most popular" End If End Sub 

正如在评论中提到的那样,事实上你将有大约50个小小的评估不会减慢你的代码(除非评估中有一个非优化函数,或者你正在访问一个数据库)。