If ElseIf Statement

If Then Else

It is the same as If Then Statement, however you have another option if the argument is false.

Let's use the example from previous lesson.

Try to create the macro from example above to your vba editor

Using simple If Then statement, you only have one option. If the argument is False, then it will end the subroutine.
On the other hand, If Else Statement has another option.

Try to change the name other than Richard so that you will know how it works.

If then ElseIf 
What if you have more than one argument or condition?
Thus, we can use the else if statement.


In the example above, you have now two arguments.
First one is to check the value of Range A1 is Richard.
Second one is to check the value of Range A1 is Mark.

What if these two arguments are all false?
This where Else is used.

Homework:
1. Create a cascaded If Else statement inside a For Loop.
2. Check whether there is value inside range A1 to A10.
3. Then, if have value, then check again if the text is bold.

If you have some clarifications you can make comment below.

Our next lesson is about Select Case Statement.






No comments:

Post a Comment