Excel 關于VBA中IF多條件語句的用法,虛心求教
IF語句的語法:
If 條件判斷語句1 Then
處理語句A
ElseIf 條件判斷語句2 Then
處理語句B
Else
處理語句C
End If其中,條件判斷語句需要使用判斷符,常用的判斷符有“==”(相等)、“>”(大于)、“>=”(大于等于)、“”(不等于)。
如果有多個并列的條件,可以使用“And”(邏輯與)、“Or”(邏輯或)來連接。
例子:
If xxx==xxx And yyyyyy Then
ElseIf xxx==yyy Or xxx
Else
End If補充:如果有多條并列條件,且要混用Or和And,不妨使用括號。
VBA if語句的條件描述
列呢?是所有列還是只有一列?以A列舉例: Dim i As Integer Dim isAllOK As Boolean isAllOK = True For i = 1 To 100 If Range("A" & i).*ndex <> xlNone Then isAllOK = False MsgBox "A" & i & "單元格不合格!" End If Next i If isAllOK = True Then MsgBox "全部合格!" End If。
求VBA三個條件選擇的語句
Sub Macro1() Dim i As Integer Dim j As Integer For j = 3 To 12 If j = 3 Or j = 5 Or j = 8 Then For i = 9 To 13 Call Judg(i, j) Next i End If i = 14 If j = 4 Or j = 6 Or j = 8 Or j = 10 Or j = 12 Then Call Judg(i, j) i = 15 If j = 4 Or j = 8 Or j = 11 Then Call Judg(i, j) Next jEnd SubSub Judg(i As Integer, j As Integer) If Trim(Cells(i, j)) = "" Or Trim(Cells(i, j)) = 0 Then Cells(i, j) = "/" Else If Trim(Cells(i, j)) < 0.01 Then Cells(i, j) = "微量" End IfEnd Sub。
excel中if語句用vba怎么寫
1. 函數中的if語句=if(條件,符合條件結果,不符合條件結果)。
2. VBA中也有一個同樣的函數,為了跟函數的if區分,vba中的名稱為iif,使用方法與函數完全一致,iif(條件,符合條件結果,不符合條件結果)。
3. VBA中另外一種if表達方式更為常用,格式為
if 條件 then 執行結果或者
if 條件 then
結果一
結果二
else if 條件
結果
end if4. VBA中的if語句常用來與for..next循環搭配使用,亦可用do while。Loop語句代替。
VBA if語句的條件描述
列呢?是所有列還是只有一列?
以A列舉例:
Dim i As Integer
Dim isAllOK As Boolean
isAllOK = True
For i = 1 To 100
If Range("A" & i).*ndex <> xlNone Then
isAllOK = False
MsgBox "A" & i & "單元格不合格!"
End If
Next i
If isAllOK = True Then
MsgBox "全部合格!"
End If
excel中if語句用vba怎么寫
函數中的if語句=if(條件,符合條件結果,不符合條件結果)。
VBA中也有一個同樣的函數,為了跟函數的if區分,vba中的名稱為iif,使用方法與函數完全一致,iif(條件,符合條件結果,不符合條件結果)。VBA中另外一種if表達方式更為常用,格式為if 條件 then 執行結果或者 if 條件 then結果一結果二else if 條件結果end if4. VBA中的if語句常用來與for..next循環搭配使用,亦可用do while。
Loop語句代替。
求VBA三個條件選擇的語句
Sub Macro1()
Dim i As Integer
Dim j As Integer
For j = 3 To 12
If j = 3 Or j = 5 Or j = 8 Then
For i = 9 To 13
Call Judg(i, j)
Next i
End If
i = 14
If j = 4 Or j = 6 Or j = 8 Or j = 10 Or j = 12 Then Call Judg(i, j)
i = 15
If j = 4 Or j = 8 Or j = 11 Then Call Judg(i, j)
Next j
End Sub
Sub Judg(i As Integer, j As Integer)
If Trim(Cells(i, j)) = "" Or Trim(Cells(i, j)) = 0 Then
Cells(i, j) = "/"
Else
If Trim(Cells(i, j)) < 0.01 Then Cells(i, j) = "微量"
End If
End Sub