|
'VBA中的IF条件判断语句,就像函数中的IF一样
'IF可单条件,也可多条件。
Sub IF条件判断之单条件1()
Dim a%, b%
a = 2
b = 2
If a = b Then MsgBox "相等"
End Sub
Sub IF条件判断之单条件2()
Dim a%, b%
a = 2
b = 2
If a = b Then
MsgBox "相等"
End If
End Sub
Sub IF条件判断之单条件3()
Dim a%, b%
a = 2
b = 2
If a = b Then
MsgBox "相等"
Else
MsgBox "不相等"
End If
End Sub
Sub IF条件判断之多条件等级划分()
If Sheet1.Range("b1") >= 90 Then
Sheet1.Range("b2") = "优秀"
ElseIf Sheet1.Range("b1") >= 80 Then
Sheet1.Range("b2") = "良好"
ElseIf Sheet1.Range("b1") >= 70 Then
Sheet1.Range("b2") = "中等"
Else
Sheet1.Range("b2") = "较差"
End If
End Sub
'VBA中的IIF函数与工作表函数(IF)的语法结一致
Sub IIF函数应用()
Cells(2, 3) = IIf(Cells(1, 2) > 80, "优秀", "不优秀")
End Sub
|
|