Statement one: If Judgment statement
Sub Judgment 1 () ' Single condition judgment If Range ("A1"). Value > 0 Then range ("B1") = "positive" Else Range ("B1") = "negative or 0" End IfEnd SubSub Judge 2 () ' Multi-condition-judged If range ( "A1"). Value > 0 Then range ("B1") = "positive" ElseIf Range ("a1") = 0 Then Range ("B1") = "equals 0" ElseIf Range ("B1") <= 0 Then Range ("B1") = "negative" End IfEnd SubSub Multi-Criteria 2 () If Range ("A1") <> "and Range (" A2 ") <>" " Then range ("a3") = Range ("a1") * Range ("A2") End IfEnd Sub
Statement two: IIf function judgment
Sub Judgment 4 () Range ("a3") = IIf (Range ("A1") <= 0, "negative number or 0", "negative number") End Sub
Statement three: Select Judgment
Sub Judgment 1 () ' Single condition judging Select Case Range ("A1"). Value case is > 0 Range ("B1") = "positive" case Else Range ("B1") = "negative or 0" End selectend SubSub Judge 2 () ' Multi-condition Judge Select Case Range ("A1"). Value case is > 0 Range ("B1") = "positive" case was = 0 Range ("B1") = "0" Case Else Range ("B1") = "Negative" end SelectEnd SubSub Judgment 3 () If Range ("A3") < "G" then MsgBox "a-g" End IfEnd Sub
Statement four: Judging range
Sub if interval judgment () if range ("A2") <= (" b2") = 0.01ElseIf Range ("A2") <= then range ("b2") = 0.03 ElseIf Range ("A2") > Then Range ("b2") = 0.05End IfEnd SubSub Select Interval Judging () Select Case Range ("A2"). Value case 0 to + range ("b2") = 0.01 Case 1001 to Range ("b2") = 0.03 case is > range ("b2") = 0 . End SelectEnd Sub
Summary: VBA common judgment methods and functions
VBA Basic Knowledge ——— common statements