VBA Basic Knowledge ——— common statements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.