Logo RSS
دانلود و آموزش رایگان نرم افزار های کامپیوتر و اینتر نت و گوشی

دانلود و آموزش رایگان

پنجشنبه بیست و هشتم بهمن ۱۳۸۹

If...Then...Else Statement

       *برگرفته از راهنمای اکسل*

Conditionally executes a group of statements, depending on the value of an expression.


If condition Then [statements] [Else elsestatements]

Or, you can use the block form syntax:

If condition Then

[ElseIf condition-n Then
[elseifstatements] ...


End If

The If...Then...Else statement syntax has these parts:


Part Description
condition Required. One or more of the following two types of expressions:
  A numeric expression or string expression that evaluates to True or False. If condition is Null, condition is treated as False.
  An expression of the form TypeOf objectname Is objecttype. The objectname is any object reference and objecttype is any valid object type. The expression is True if objectname is of the object type specified by objecttype; otherwise it is False.
statements Optional in block form; required in single-line form that has no Else clause. One or more statements separated by colons; executed if condition is True.
condition-n Optional. Same as condition.
elseifstatements Optional. One or more statements executed if associated condition-n is True.
elsestatements Optional. One or more statements executed if no previous condition or condition-n expression is True.



You can use the single-line form (first syntax) for short, simple tests. However, the block form (second syntax) provides more structure and flexibility than the single-line form and is usually easier to read, maintain, and debug.

Note   With the single-line form, it is possible to have multiple statements executed as the result of an If...Then decision. All statements must be on the same line and separated by colons, as in the following statement:

If A > 10 Then A = A + 1 : B = B + A : C = C + B

A block form If statement must be the first statement on a line. The Else, ElseIf, and End If parts of the statement can have only a line number or line label preceding them. The block If must end with an End If statement.

To determine whether or not a statement is a block If, examine what follows the Then keyword. If anything other than a comment appears after Then on the same line, the statement is treated as a single-line If statement.

The Else and ElseIf clauses are both optional. You can have as many ElseIf clauses as you want in a block If, but none can appear after an Else clause. Block If statements can be nested; that is, contained within one another.

When executing a block If (second syntax), condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf condition (if any) is evaluated in turn. When a True condition is found, the statements immediately following the associated Then are executed. If none of the ElseIf conditions are True (or if there are no ElseIf clauses), the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following End If.

Tip   Select Case may be more useful when evaluating a single expression that has several possible actions. However, the TypeOf objectname Is objecttype clause can't be used with the Select Case statement.

Note   TypeOf cannot be used with hard data types such as Long, Integer, and so forth other than Object.

دسته بندی : VBA اکسل

نویسنده: علیرضا
آخرین مطالب
» ( چهارشنبه چهاردهم تیر ۱۳۹۱ )
» همه چیز در باره ی Dr.Watson ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» نصب مودم در لينوكس ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» نصب اتوماتیک و بدون دردسر ویندوز XP ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» نصب اتوماتیک و بدون دردسر ویندوز XP ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» مفهوم بيت و بايت ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» مشکل Task Manager ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» ساخت Setup به وسیله ویندوز XP ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» رفع مشكل مودم هايDSLاز نوع USB در ويندوز XP ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» توضیج کامل رجیستری ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» پاک کردن پسورد BIOS کامپیوتر ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
» از قلب ویندوز خود نسخه ی پشتیبان تهیه کنید! ( یکشنبه بیست و دوم خرداد ۱۳۹۰ )
درباره ما

دانلود و آموزش رایگان نرم افزار های کامپیوتر و اینتر نت و گوشی
سلام دوست عزیز
به وبلاگ من خوش امددید!

دوستان عزيز لطف شماروميرسونه بعدازهرمطلبي نظرات خودتون رو ارسال کنید
تاوبلاگم به هرآن چه كه شما انتظارش رو داريد تغيير پيداكنه


در ضمن برای لینک کردن نظر بزار لینکت میکنم!
ایمیل : alirezza9648@yahoo.com