Make it positive

L

LRogers81

Here's the situation, I have a problem that has 20 units purchased and
I receive a 7% discount for over 20 units purchased. Cost per unit is
$52. Therefore, in the following If statement, the total would be 20
* $52 * .07 = 72.8 then take this total and subtract if from 20 * $52
which should equal $967.2 but I get a negative with my statement. I
think it's easy but I don't see it, please advise...thanks...

Dim foundRowNum As Integer
Dim numberPurchasedStr As String
Dim totalSpent As Currency
Dim unitCostRow As Currency
Dim discountRow As Double

If (CInt(numberPurchasedStr) >= Range("C" & foundRowNum).Value) Then
totalSpent = CDbl(numberPurchasedStr) * unitCostRow *
discountRow _
- CDbl(numberPurchasedStr) * unitCostRow
 
G

Guest

You formula is backwards. You are subtracting the 1040 from 72.8 rather than
subtracting 72.8 form 1040

Here is the easy fix:

Sub AAA()

Dim numberPurchasedStr As String
Dim totalSpent As Currency
Dim unitCostRow As Currency
Dim discountRow As Double
numberPurchasedStr = "20"
unitCostRow = 52
discountRow = 0.07

totalSpent = -CDbl(numberPurchasedStr) _
* unitCostRow * discountRow _
+ CDbl(numberPurchasedStr) * unitCostRow
Debug.Print CDbl(numberPurchasedStr) _
* unitCostRow * discountRow, _
CDbl(numberPurchasedStr) * unitCostRow, _
totalSpent
End Sub

produces
72.8 1040 967.2
 
L

LRogers81

Aye, it was that simple...thanks a bunch...

You formula is backwards. You are subtracting the 1040 from 72.8 rather than
subtracting 72.8 form 1040

Here is the easy fix:

Sub AAA()

Dim numberPurchasedStr As String
Dim totalSpent As Currency
Dim unitCostRow As Currency
Dim discountRow As Double
numberPurchasedStr = "20"
unitCostRow = 52
discountRow = 0.07

totalSpent = -CDbl(numberPurchasedStr) _
* unitCostRow * discountRow _
+ CDbl(numberPurchasedStr) * unitCostRow
Debug.Print CDbl(numberPurchasedStr) _
* unitCostRow * discountRow, _
CDbl(numberPurchasedStr) * unitCostRow, _
totalSpent
End Sub

produces
72.8 1040 967.2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top