VBA Judgment statement

Source: Internet
Author: User
Tags expression numeric range valid

The variables and operators in the three major elements of the code are described earlier, and the judgment statement in the statement is now in the following ways:

1, If condition Then [Statements][else elsestatements].

Description of each part:

Partial description

Condition necessary parameters. One or more expressions with the following two types:

A numeric expression or string expression that evaluates to TRUE or False. If condition is Null, condition is treated as False.

An expression in the form of TypeOf objectname is objecttype. The objectname is a reference to any object, and objecttype is any valid object type. If objectname is an object type specified by objecttype, the expression is True or false.

Statements is optional if there is no Else clause, the necessary argument. They are executed when condition is true.

Elsestatements Optional Parameters. They are executed when the previous condition or condition-n are not true.

2, If condition Then

[Statements]

[ElseIf condition-n Then

[Elseifstatements] ...

[Else]

[Elsestatements]]

End If

Description of each part:

Partial description

Condition necessary parameters. One or more expressions with the following two types:

A numeric expression or string expression that evaluates to True or False. If condition is Null, condition is treated as False.

An expression in the form of TypeOf objectname is objecttype. The objectname is a reference to any object, and objecttype is any valid object type. If objectname is an object type specified by objecttype, the expression is True or false.

Statements Optional parameters. One or more statements separated by colons, which are executed when condition is True.

Condition-n Optional Parameters. The same with condition.

Elseifstatements Optional Parameters. One or more statements that are executed when the associated condition-n is True.

Elsestatements Optional Parameters. One or more statements that are executed when the previous condition or condition-n are not true.

3, IIf function. The IIf function is not a statement, but because it can replace the If ... Then, it is summed up here, its syntax is as follows:

IIf (expr, Truepart, Falsepart)

Description of each part:

Partial description

Expr necessary parameters. An expression used to determine authenticity.

Truepart necessary parameters. If expr is True, this part of the value or expression is returned.

Falsepart necessary parameters. If expr is False, this part of the value or expression is returned.

4. Select Case testexpression

[Case Expressionlist-n

[Statements-n]] ...

[Case Else

[Elsestatements]]

End Select

Description of each part:

Partial description

testexpression necessary parameters. Any numeric expression or string expression.

Expressionlist-n If a case appears, it is the necessary parameter. A list of one or more constituent boundaries in the form of expression,expression to expression,is comparisonoperator expression. The To keyword can be used to specify a range of values. If you use the To keyword, the smaller values appear before to. When you use the IS keyword, you can specify a range of values with the comparison operator (except is and like). If not provided, the IS keyword is automatically inserted.

Statements-n Optional Parameters. One or more statements that are executed when testexpression matches any part of the expressionlist-n.

Elsestatements Optional Parameters. One or more statements that are executed when testexpression does not match any part of the case clause.

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.