IF ELSE Function Using VBA in Excel

The IF-ELSE function in Microsoft Excel is one of the most versatile functions and it is very difficult to avoid using this function in solid calculations or analysis.
‘If’ helps the user to calculate a value if a condition evaluates to TRUE and another value if the condition evaluates to FALSE. Syntax: IF (logical_test,value_if_true,value_if_false)
For example, you could give the buyer of your goods a discount of 10% if she purchases a quantity greater than or equal to 12 of a product and a discount of 5% if she purchases a quantity less than 12.
The code for the above macro is given below.
Sub how_to_use_if_else()
Range(“D4”) = Range(“C4”) * Range(“B4”)
If Range(“B4”) >= 12 Then
Range(“E4”) = Range(“D4”) * 0.1
Range(“E4”) = Range(“D4”) * 0.05
End If
Range(“F4”) = Range(“D4”) – Range(“E4”)
Range(“F4”) = Round(Range(“F4”), 2)
End Sub
The if-else function macro first calculates the ‘Amount’ based on the quantity purchased and the price of the item. The next step determines whether the purchaser bought a quantity greater than or equal to 12. If true the discount of 10% is given else a discount of 5% is given. Next the final amount due from the customer is calculated. The final amount is then formatted to two decimal places.
Watch the training video below to see the macro in action.

3 thoughts on “IF ELSE Function Using VBA in Excel

  1. Dear sir…
    Thankful to you, I have started to watch your daily updated video. This will be much more effective if you guide how to add loop with the if else condition using VBA code. In my Project I used to calculate Amount outstanding of debt that has taken from either formal sector or informal sector, If formal sector it will be compound interest rate if not simple interest rate, but I want to continue until there is blank row in source of borrowing….Please can you guide me.

    Personally I am requesting you can you guide me, I am in begging stage of learning the VBA, which hard copy should I follow to concrete my base in VBA?

    Amalendu Das

  2. Dear Sir,

    Thankful to you, I have started to watch your daily updated video. it is very useful.

    and please help me on below doubts

    How to find if more than 1 unites used for specific code in particular account

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.