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,不妨使用括號。
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 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怎么寫
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語句代替。
excel中if語句用vba怎么寫
Public Function dj(A As Integer)
Dim Rst As String
Rst = ""
Select Case A
Case Is >= 80
Rst = "A"
Case Is >= 60
Rst = "B"
Case Else
Rst = "C"
End Select
dj = Rst
End Function
這是自定義函數,帶一個參數,返回等級.使用方法請參考Excel函數.
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 VBA if 循環語句
Dim i%, a%
a = Sheets("source data from 201010 to (2)").Range("h1").*
For i = 2 To a
If Cells(i, 6).Value = "NB" Then
Cells(i, 1) = Cells(i, 6).Value
Cells(i, 2) = Cells(i, 7).Value
Cells(i, 3) = Cells(i, 8).Value
END IF
Next i
沒有加END IF朋友!
EXCEL VBA怎么實現IF語句 .
if cells(6,2)=1 then
cells(7,3)=cells(7,8)
elseif cells(6,2)=2 then
cells(7,3)=cells(8,8)
elseif cells(6,2)=3 then
cells(7,3)=cells(9,8)
endif
注意 cells(i,j) i表示第多少行,j表示第多少列
比如c7 表示的是第7行,第3列的單元