if 判断语句
- 1.单条件判断
Sub 判断1() #单条件判断
If Range("a8").Value > 0 Then
Range("b8") = "正数"
End If
End Sub
Sub 判断2()
If Range("a8").Value > 0 Then
Range("b8") = "正数"
Else
Range("b8") = "负数或0"
End If
End Sub
- 多条件判断
Sub 判断()
If Range("a8").Value > 0 Then
Range("b8") = "正数"
ElseIf Range("a8").Value = 0 Then
Range("b8") = "等于0"
Else
Range("b8") = "负数"
End If
End Sub
Sub panduan1()
If Range("a11") <> "" And Range("b11") <> "" Then
Range("c11") = Range("a11") * Range("b11")
End If
End Sub
select case 判断
Sub 判断5()
Select Case Range("a15") '选择一个做判断的case(对象)‘
Case 1000 to 3000
Range("b15") = "0.01"
Case Else
Range("b15") = "0.03"
End Select
End Sub
Sub 判断5()
Select Case Range("a15") '选择一个做判断的case(对象)‘
Case Is > 0
Range("b15") = "正数"
Case Is = 0
Range("b15") = "0"
Case Else
Range("b15") = "负数"
End Select
End Sub
Sub 判断8()
Select Case Range("a18") '选择一个做判断的case(对象)‘
Case Is < 1000
Range("b18") = "0.01"
Case Is < 3000
Range("b18") = "0.03"
Case Is > 3000
Range("b18") = "0.05"
End Select
End Sub
IIf 判断
同在excel中的if函数用法格式,但是不能加and,也不能嵌套if
Sub panduan6()
Range("b16") = IIf(Range("a16") > 0, "正数", "负数或0")
End Sub
网友评论