Académique Documents
Professionnel Documents
Culture Documents
Condition Statement
Condition: If we have multiple situation with multiple result then
we have to use condition statement (IF)
IF EndIF
IF Else EndIF
Nested Ifs
_______________
_______________
else
_______________
_______________
End if
End if
E.g. if a>100 then
E.g. if a>100 then
msgbox a msgbox a
End if else
msgbox Other
End if
IF ELSEIF .. Condition Statement
Syntax: E.g.
Msgbox a
_______________
Elseif a<200 then
elseif condition then
Msgbox <200
_______________
Else
else
Msgbox >200
_______________ End if
End if
Nested IF Condition Statement
Syntax: E.g.
Msgbox a
_______________
Else
else
if a<200 then
if condition then
Msgbox <200
_______________
Else
else Msgbox >200
_______________ End if
end if End If
End if
Loop
Loop: If we want to carry out a set of actions to repeat a
number of times then use Loop
For Loop
Do While Loop
Do Loop While
Do Until Loop
Do Loop Until
______________________
Next [VarName]
For = Keyword , VarName = any user defined variable name
Msgbox I
Next
Msgbox I
Next I
next
______________________
Loop
Do While = Keyword
Msgbox a
a=a+1
loop
2) Do While a>0
Msgbox a
a=a-1
loop
Syntax: Do
______________________
Msgbox a
a=a+1
2) Do
Msgbox a
a=a-1
______________________
Loop
Do Until = Keyword
Msgbox a
a=a+1
loop
2) Do Until a>0
Msgbox a
a=a-1
loop
Syntax: Do
______________________
Msgbox a
a=a+1
2) Do
Msgbox a
a=a-1
______________________
Next [VarName]
For = Keyword
In = Keyword
Msgbox sht.name
Next sht
Msgbox book.name
Next book
.property1
.property2
__________
End With
With = keyword
.value =20
.font.bold =true
.color=65536
.borders.linestyle = xlContinous
End With
2) With Activesheet
.name= sht
End with
If a<10 then
Goto disp
Else
Msgbox a>=10
End if
Exit sub
Disp:
End Sub
Case case1
__________________
Case else
__________________
End select