Write the function in excel using VBA You have a company tha


Write the function in excel using VBA
You have a company that sells widgets and you want to encourage large orders. Write a function that takes the selling price and number ordered and returns the total cost of the order using the table below. Only apply the discount to numbers that fall within the listed ranges. For example, if 15 widgets that cost $13.25 each are ordered, the first 10 receive no discount and the next five get a 7% discount for a cost of $ 194

Solution

Function Discount(widgets, price)

Dim dis as Integer
Dim dis1 as Integer
Dim dis2 as Integer

If widgets <=10 Then
    Discount = price * widgets

ElseIf widgets > 10 Or widgets < = 20 Then
    dis = price * (widgets - 10)
    Discount = dis - (0.07*dis) + price * 10

ElseIf widgets > 20 Or widgets < = 30 Then
    dis = price * 10 - price * 10 * 0.07
dis1 = price * (widgets - 20)
    Discount = dis1 - (0.14*dis1)+ dis + price * 10


Else
  
    dis = price * 10 - price * 10 * 0.07
dis1 = price * 10 - price * 10 * 0.14
dis2 = price * (widgets - 30)
    Discount = dis2 - (0.20*dis2)+ dis1 + dis + price * 10



End If

Discount = Application.Round(Discount, 2)
End Function

 Write the function in excel using VBA You have a company that sells widgets and you want to encourage large orders. Write a function that takes the selling pri

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site