-
Dec 3rd, 2017, 07:10 PM
#1
Thread Starter
New Member
Excel-Visual Basic UserForm Coding
Been trying to do a VBA Excel sheet that calculates the cost of a pizza by size with x toppings. I have made a command button that calls a userform that lets the user select the size and toppings that the person wants. What im stuck on is getting the toppings added with the size the user selected to print to the messagebox, it prints just whatever the size of the pizza is right now. I also need to get the message box to tell the user what toppings they selected as well as the size, with the option to cancel the order but i think i can do that with an if-else statement. I just need help with the whole computation part. ill include the spreadsheet. Since i cant upload the PizzaProject.xlsm i used dropbox, https://www.dropbox.com/s/nooktpavao...ject.xlsm?dl=0
-
Dec 4th, 2017, 03:16 AM
#2
Re: Excel-Visual Basic UserForm Coding
Since i cant upload the PizzaProject.xlsm
zip first
you can test his to see if it works as you require
Code:
Private Sub cmdOrder_Click()
Dim blnSelect As Boolean
Dim curTotalCost As Currency
Dim curStartCost As Currency
Dim curToppings As Currency
Dim ssize As String, sTotalCost As String, stops As String
blnSelect = True
curToppings = 1.5
stops = "Selected toppings "
For Each c In Me.Controls
If TypeOf c Is msforms.CheckBox Then
If c.Value Then
stops = stops & c.Caption & " "
curTotalCost = curTotalCost + curToppings
End If
End If
Next
For Each c In Me.Controls
If TypeOf c Is msforms.OptionButton Then
If c.Value Then
ssize = c.Caption
curTotalCost = curTotalCost + WorksheetFunction.VLookup(ssize, Range("A4:b6"), 2)
Exit For
End If
End If
Next
sTotalCost = FormatCurrency(curTotalCost)
stops = stops & "on a " & ssize & "Base" & vbNewLine & "Total cost " & curTotalCost
If MsgBox(stops, vbOKCancel, "My Pizza") = vbCancel Then
ClearControls
curToppings = 0
Else
Range("b7").Value = sTotalCost
Unload Me
End If
End Sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|