VBA Decisions If Statements
Programmers can regulate how a script or a portion of it is executed by using decision-making.
One or more conditional statements control the execution.
In VBA, decision-making statements allow you to control the flow of your program based on specific conditions. One of the most fundamental decision-making structures is the If...Then...Else
statement.
If Statement: An if statement consists of a Boolean expression followed by one or more statements.
If else Statement: An if else statement consists of a Boolean expression followed by one or more statements. If the condition is True, the statements under If statements are executed. If the condition is false, the Else part of the script is executed.
If, elseif, else Statement: An if statement followed by one or more ElseIf
statements, that consists of Boolean expressions and then followed
by an optional else statement, which executes when all the condition
become false.
Nested If Statement: An If or ElseIf statement enclosed within another If or ElseIf statement or statements is known as a “nested if.” The topmost If statements serve as the basis for the execution of the inner If statements. This makes it possible for VBScript to easily handle complex circumstances.
Let’s use a function to determine the type of a positive number
Switch Statement: An If or ElseIf statement enclosed within another If or ElseIf statement or statements is known as a “nested if.” The topmost If statements serve as the basis for the execution of the inner If statements. This makes it possible for VBScript to easily handle complex circumstances.
Let’s use a function to determine the type of a positive number.