UDF command reference
I am just studying Excel 2007 VBA programmer's Reference book. On that chaper 1: Primer in Excel VBA there is a UDF example as below.
In the command line InvoiceAmount = Price * DiscountVolume + Price * _
(1 - DiscountPct) * (Volume - DiscountVolume)
what the command (1 - DiscountPct) refers. What the command meaning to (1 - DiscountPct). Can someone explain to me?
Function InvoiceAmount(Product, Volume)
'Create object variable reffering to table in worksheet
Set Table = ThisWorkbook.Worksheets("Sheet1").Range("A2:D5")
'Find price in table
Price = WorksheetFunction.VLookup(Product, Table, 2)
'Find discount volume threshold
DiscountVolume = WorksheetFunction.VLookup(Product, Table, 3)
'Appy discount if volume above threshold
If Volume > DiscountVolume Then
'Calculate invoice with discount
DiscountPct = WorksheetFunction.VLookup(Product, Table, 4)
InvoiceAmount = Price * DiscountVolume + Price * _
(1 - DiscountPct) * (Volume - DiscountVolume)
Else
'Calculate invoice without discount
InvoiceAmount = Price * Volume
End If
End Function
|