In our example, orders over $15 qualify for free shipping.
Here we want to calculate if the order qualifies for free shipping so we can filter and identify them.
We are going to create a user defined, custom function and pass the price as the only argument, and return the result of “True” or “False”
This is the list we are going to evaluate.
The function used to determine if the order qualifies for free shipping is a custom function called “FreeShipping(dblPrice)”
Here is the code for our new function:
Function FreeShipping(dblPrice) As String If dblPrice > 14.99 Then FreeShipping = "True" Else FreeShipping = "False" End If End Function
If the price (dblPrice) is greater than “14.99”, the order will qualify for free shipping.
I am calling the argument “dblPrice” because it’s a “double” datatype. I could be more confusing and write the function this way (but I didn’t):
Function FreeShipping(dblPrice as Double) As String If dblPrice > 14.99 Then FreeShipping = "True" Else FreeShipping = "False" End If End Function
Essentially, we are passing in a “Double” value and returning a “String” value.
Why do you use the IF function in Excel?
You normally use the If statement to control the program flow, make decisions. Basically, if the variable meets a certain condition, do this, and if not, do something else.
Watch me do it:
Let me know if you have any questions