L
LRogers81
With a lot of help, the code inputed below is for an excel file. The
crux of the situation is that the program has to check
Range("A4:A131") to see if the product code entered is in the list and
if it is then it asks for user input to see how many units the person
purchased. If it is over a certain amount then it applies a discount,
if not then no discount is applied. The following is what the cells
look like.
Problem 1) When I run the sub, however, it just loops right on
through without breaking so I Ctrl-Break into it and get out of the
program.
Problem 2) I need to know how to apply the discount and put it in
cell E4, is what I have under the If statement good enough or not (#1
it doesn't check itself against the Minimum purchase qty or unit cost,
that could be a problem)
Product code Unit cost Minimum purchase quantity for discount Discount
C3972 $52
20 7%
Sub PriceData2()
Dim productRow As String
Dim foundRowNum As Integer
Dim i As Integer
Dim numberPurchasedStr As String
productRow = InputBox("Enter the product code")
i = 4
Do Until i = 131
If Range("A" & i).Value = productRow Then
foundRowNum = i
MsgBox "The row for product " & productRow & " is " &
foundRowNum & ".", _
vbInformation
Exit Do
End If
Loop
numberPurchasedStr = InputBox("Enter the number purchased")
If (CInt(numberPurchasedStr) >= Range("C" & foundRowNum).Value)
Then
With Range("E4")
.Offset(numberPurchasedStr, 0) = numberPurchasedStr
End With
Range("E4") = Range("B14")
' Apply discount
Else
' Do not apply discount
End If
End Sub
Thanks,
-Lee
crux of the situation is that the program has to check
Range("A4:A131") to see if the product code entered is in the list and
if it is then it asks for user input to see how many units the person
purchased. If it is over a certain amount then it applies a discount,
if not then no discount is applied. The following is what the cells
look like.
Problem 1) When I run the sub, however, it just loops right on
through without breaking so I Ctrl-Break into it and get out of the
program.
Problem 2) I need to know how to apply the discount and put it in
cell E4, is what I have under the If statement good enough or not (#1
it doesn't check itself against the Minimum purchase qty or unit cost,
that could be a problem)
Product code Unit cost Minimum purchase quantity for discount Discount
C3972 $52
20 7%
Sub PriceData2()
Dim productRow As String
Dim foundRowNum As Integer
Dim i As Integer
Dim numberPurchasedStr As String
productRow = InputBox("Enter the product code")
i = 4
Do Until i = 131
If Range("A" & i).Value = productRow Then
foundRowNum = i
MsgBox "The row for product " & productRow & " is " &
foundRowNum & ".", _
vbInformation
Exit Do
End If
Loop
numberPurchasedStr = InputBox("Enter the number purchased")
If (CInt(numberPurchasedStr) >= Range("C" & foundRowNum).Value)
Then
With Range("E4")
.Offset(numberPurchasedStr, 0) = numberPurchasedStr
End With
Range("E4") = Range("B14")
' Apply discount
Else
' Do not apply discount
End If
End Sub
Thanks,
-Lee