AND功能在VBA中如何工作? [英] How does AND function work in VBA?

查看:464
本文介绍了AND功能在VBA中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,如果这是一个愚蠢的问题,但是(Excel VBA)AND函数是否先检查其中的每个单个条件,然后继续进行操作,还是在第一个FALSE条件下停止而不检查另一个条件?我想知道出于优化目的,到目前为止在网络上什么都没有找到..预先感谢!

I'm sorry if this is a stupid question, but does the (Excel VBA) AND function checks EVERY single condition in it then proceed, or stops at the first FALSE condition and not checks the other? I'd like to know for optimization purposes and found nothing about it on the web so far.. Thanks in advance!

示例:如果InStr(txt,"abc")> 0和InStr(txt,"xyz")> 0然后

Example: If InStr(txt, "abc") > 0 And InStr(txt, "xyz") > 0 Then

因此,如果在txt变量中未找到"abc"(给出"false"),则宏也会检查"xyz"还是跳过其余条件

so if "abc" not found in the txt variable (gives 'false'), then will the macro check the "xyz" too or skip the rest conditions

推荐答案

VBA似乎一直在继续:

It appears that VBA keeps on going:

Sub ANDTest()
    If f1() And f2() Then MsgBox "X"
End Sub

Public Function f1() As Boolean
    f1 = False
End Function

Public Function f2() As Boolean
    MsgBox "in f2"
    f2 = False
End Function

这篇关于AND功能在VBA中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆