If the Random number is less than 5: Let’s consider the random number generated is 3. (I know it’s a weird message, but I just used it for helping you to understand the things.)Īfter this, the program control directly jumps to Line-10, skips the ELSE part, and comes out of the whole IF statement. So, it pops up a message saying “ 5 is equal to 5”. So, it skips the IF Block and jumps to the ELSEIF statement, here it checks ‘ If 5 = 5’ which evaluates to TRUE. In this case, when the program control reaches Line-4, it checks ‘ If 5 > 5’, which is FALSE. If the Random number is equal to 5: Let’s consider the random number generated is 5. After this, it directly jumps to the Line-10 and comes out of the whole IF Statement. So, it jumps to the instruction immediately beneath it and pops up a message saying “ 7 is greater than 5”. When it reaches Line-4 it checks ‘ If 7 > 5’, which is TRUE. The program starts from Line-1 and executes all the instructions sequentially till Line-4. If the Random number is greater than 5: Let’s consider the random number generated is 7. After this, we have used an IF statement to check whether this number is greater than 5, equal to 5, or less than 5.īased on the generated number, any one of the three conditions will evaluate to TRUE, and a suitable message box will pop out.
#Valorant aim lab routine code
Num = WorksheetFunction.RandBetween( 1, 10)Įxplanation: In the above code we have used the RandBetween function of Excel to generate any random number from 1 – 10. So, we will try to write a VBA program as: Objective: Here we will generate a random number between 1-10 and then our task is to identify if the generated number is less than 5, equal to 5 or greater than 5.
#Valorant aim lab routine how to
Now let’s understand how to use the IF Statement in VBA.īefore preceding let’s make our objective very clear. Note: Remember that out of IF, ELSEIF’s, and ELSE code blocks only a single code block will be executed at a time based on the condition. Finally, if all the IF and ELSEIF’s evaluate to FALSE then the ELSE block will be executed. However, in case, it also evaluates to FALSE then the next ELSEIF statement will be evaluated and so on. If it evaluates to TRUE then the instructions inside the ELSEIF Block will be sequentially executed and the rest of the blocks (ELSEIF’s and ELSE blocks) will be skipped. This means, first of all, the IF Statement with ‘ condition_1’ will be evaluated, if it evaluates to TRUE then statements inside the first IF block will be executed and the rest of the blocks (ELSEIF’s and ELSE blocks) will be skipped.īut, if the First IF Statement evaluates to FALSE then the ELSEIF statement following it will be evaluated. The conditions along with the IF Statements will be evaluated sequentially. IF function usually ends with an ‘ END IF’ statement which tells the application that it is the last line of the IF function. The ‘ THEN’ keyword is basically a directive signifying that the instructions immediately following the IF Statement are to be executed if the condition evaluates to TRUE. either it should be TRUE or it should be FALSE). Here, ‘ condition_1’ to ‘ condition_n’ refers to the expression that must evaluate to a Boolean value (i.e. Recommended Reading: Nested IF’s in Excel In such a case, if the condition inside IF statement evaluates to FALSE then the program control just moves to the next instruction (the instruction after the IF Block) and starts executing them sequentially. However, if the condition evaluates to FALSE then it takes the program control to the statements inside the Else Block.Īlthough, it is not mandatory to have an Else Block with every IF statement. If the condition evaluates to TRUE then, it simply takes the program control to the instructions inside the IF block and starts executing them sequentially.
On the other hand, VBA IF Statement checks a condition but it doesn’t return any value. The IF Function in Excel and the IF Statement in VBA are basically designed to do the same tasks, but the way they work is slightly different from each other.Įxcel IF function checks a particular condition and if the condition is TRUE, it returns one value otherwise it returns the second value. If you have followed my earlier posts, then you would remember that we discussed If Function in Excel. The task of the IF Statement is to check if a particular condition is met or not. IF statement in VBA is sometimes also called as IF THEN ELSE Statement. IF is one of the most popular and frequently used statements in VBA.