0% found this document useful (0 votes)
4 views2 pages

Rice Price Calculator in VBA

The document is a VBA code for a user form that manages rice sales, allowing users to select rice types and input quantities. It calculates total costs with a discount for bulk purchases and displays the total amount due at checkout. The form initializes with predefined rice prices and updates the total as items are added to the cart.

Uploaded by

Nas Ambola
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Rice Price Calculator in VBA

The document is a VBA code for a user form that manages rice sales, allowing users to select rice types and input quantities. It calculates total costs with a discount for bulk purchases and displays the total amount due at checkout. The form initializes with predefined rice prices and updates the total as items are added to the cart.

Uploaded by

Nas Ambola
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Option Explicit

Dim ricePrices As Object


Dim totalAmount As Double

Private Sub UserForm_Initialize()


Set ricePrices = CreateObject("[Link]")

' Suggested Retail Price (SRP) per kilo


[Link] "Sinandomeng", 45
[Link] "Dinorado", 50
[Link] "Jasmine", 55
[Link] "Malagkit", 60

Dim key As Variant


For Each key In [Link]
[Link] key
Next key

totalAmount = 0
[Link] = "Total: ₱0.00"
End Sub

Private Sub cmdAdd_Click()


Dim riceType As String
Dim kilos As Double
Dim pricePerKilo As Double
Dim discount As Double
Dim finalPrice As Double
Dim lineTotal As Double

If [Link] = -1 Then
MsgBox "Please select a rice type.", vbExclamation
Exit Sub
End If

If Not IsNumeric([Link]) Or Val([Link]) <= 0 Then


MsgBox "Enter a valid number of kilos.", vbExclamation
Exit Sub
End If

riceType = [Link]
kilos = Val([Link])
pricePerKilo = ricePrices(riceType)
' Apply wholesale discount: 5% off if kilos >= 25
If kilos >= 25 Then
discount = 0.05
Else
discount = 0
End If

finalPrice = pricePerKilo * (1 - discount)


lineTotal = kilos * finalPrice

[Link] riceType & " - " & kilos & "kg @ ₱" & Format(finalPrice, "0.00") & " = ₱" &
Format(lineTotal, "0.00")

totalAmount = totalAmount + lineTotal


[Link] = "Total: ₱" & Format(totalAmount, "0.00")

' Clear inputs


[Link] = -1
[Link] = ""
End Sub

Private Sub cmdCheckout_Click()


If [Link] = 0 Then
MsgBox "Cart is empty!", vbInformation
Exit Sub
End If

MsgBox "Total Amount Due: ₱" & Format(totalAmount, "0.00"), vbInformation, "Checkout"

' Reset
[Link]
totalAmount = 0
[Link] = "Total: ₱0.00"
End Sub

You might also like