可以用if elseif else,也可以用select case,示例代码如下:(1)if elseif;12345678910111213141516 Subif_sample() Dimi AsInteger Fori = 1 To300 Ifi = 1 Then Debug.Print "i值等于1" ElseIfi = 20 Then Debug.Print "i值等于20" ElseIfi = 40
vba中的多条件if,一般有两种情况:一是使用and、or连接多个条件,例如:if a1=1 and a2=2 or a2="" then二是使用if嵌套,例如:if a1=1 then if a2=2 then else else if a2="" then else end if
Sub mysub() Dim y y = InputBox("请输入测试值!") Select Case y Case 16, 32, 64 MsgBox "ok" Case Else MsgBox "wrong" End Select End Sub
if ((xxx) and (xxxx) or (xxxx)) then elseif ((xxx) and (xxxx) or (xxxx)) then endif
=if(a2>0,"天津","")&if(b2>0,"北京","")&if(c2>0,"山东","") 就是如果天津、北京下面的大于0,山东的数字小于0,那么应该得出北京,天津,山东可以未空是要得到北京,还是北京和天津?
=if(W条件,IF(A条件,数值,IF(B条件,数值,IF(C条件,数值,IF(D条件,IF(M条件,数值,IF(N条件,数值,"")),"")))))
多条件的情况一般是先分析条件的范围,有大范围,有小范围比如从一个数组中,先找整数,再找大于某个值的,再找符合具体条件的按这个编写IF语句即可
输入=IF(OR(A1=1,A1=2),"true","false")
在G1单元格中输入=IF(AND(A1=B1,C1=D1,E1=F1),K1,0)
用下面的代码 具体自己调整 sub abc() dim xx, x1, x2 xx=0 for n=5 to 500 if range("a" & n).value=x1 and range("b" & n).value=x2 then xx=xx+range("d" & n).value end if end sub