
Step 4: Start the loop for the next cell. Step 3: Declare a variable X as Long and write the if statement as below,
#Vba code in excel code#
Step 2: In the code window, declare the subfunction, If the sales done by the employees is equals to or above 10000 they will receive the incentive. The incentive criteria are 10000 for this example.

If their sales are equals to specific criteria or greater than that then they will receive the incentive or there will be no incentive for those employees. We have the following data, Name of the employees and sales done by them. Let use VBA OR function in a real scenario. Step 6: Run the above code from the run button and we will get the following result displayed.Īs one of the conditions were true we have the above result. Step 5: Write a personalized message if any of the logical conditions is true or even if it is false. Step 4: Now write the if statement for the given variables, for example, like in the code given below, Step 3: Define all the four variables A B C and D as integers and assign them random values.ĭim A As Integer Dim B As Integer Dim C As Integer Dim D As Integer Step 2: A code window will appear on the right-hand side of the screen. Steps 1: Now once we are in VB Editor go ahead and insert a new module from the insert section. This time we will use a personalized message to display using or and if function. Earlier we used another variable to store the Boolean value of OR function and display it. Now let us use OR Function in VBA with the IF function. One of the values of the condition were returned as true so our final output is also returned as true. Why we get the value as True because A is less than B and C is not greater than D. Step 8: Run the code above from the run button as shown and we will see the following result as we run the above code. Step 1: Now once we are in VB Editor go ahead and insert a new module from the insert section.


And we will see what will be the result displayed by the code. I mean to say that this time our expression for X will be AD. Now let us interchange the values for X from example 1. Both of the values of the condition were returned as false so our final output is also returned as false. Why we get the value as false because A is not greater than B and C is not greater than D. Step 8: Run the code from the run button provided in the screenshot below and then we see the following result when we run the above code. Step 7: Now we will display the value of X stored in it. Step 6: Define X’s Values as conditions for A B C and D. Step 5: Assign Random Values to A B C and D.ĭim A As Integer Dim B As Integer Dim C As Integer Dim D As Integer Dim X As String Step 4: Define a variable X to store the value of OR Function, define it as a string.ĭim A As Integer Dim B As Integer Dim C As Integer Dim D As Integer Dim X As String End Sub Step 3: Define the four variables A B C and D as integers.ĭim A As Integer Dim B As Integer Dim C As Integer Dim D As Integer End Sub
