Dashboard Mode - UserForm basics
Dashboard Goal
Help users enter sales data easily using a UserForm in Excel. The dashboard shows how to input data through the form and see it listed in the sheet.
Help users enter sales data easily using a UserForm in Excel. The dashboard shows how to input data through the form and see it listed in the sheet.
| Sale ID | Product | Quantity | Price | Total |
|---|---|---|---|---|
| 1 | Pen | 10 | 1.5 | 15 |
| 2 | Notebook | 5 | 3 | 15 |
| 3 | Eraser | 7 | 0.5 | 3.5 |
| 4 | Marker | 3 | 2 | 6 |
| 5 | Ruler | 4 | 1 | 4 |
=C2*D2 calculates total price per sale.Private Sub btnAdd_Click()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("SalesData")
Dim nextRow As Long
nextRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row + 1
ws.Cells(nextRow, 1).Value = nextRow - 1 ' Sale ID
ws.Cells(nextRow, 2).Value = Me.txtProduct.Value
ws.Cells(nextRow, 3).Value = Val(Me.txtQuantity.Value)
ws.Cells(nextRow, 4).Value = Val(Me.txtPrice.Value)
Me.txtProduct.Value = ""
Me.txtQuantity.Value = ""
Me.txtPrice.Value = ""
Me.txtProduct.SetFocus
End Sub+----------------------+-------------------------+
| UserForm | Sales Data Table |
| [Product: ] | +----+---------+-----+-----+|
| [Quantity: ] | | ID | Product | Qty | $ | |
| [Price: ] | +----+---------+-----+-----+|
| [Add Button ] | | 1 | Pen | 10 | 1.5 |
+----------------------+ | 2 | Notebook| 5 | 3 |
| 3 | Eraser | 7 | 0.5 |
| 4 | Marker | 3 | 2 |
| 5 | Ruler | 4 | 1 |
+----+---------+-----+-----+
When the user types product name, quantity, and price in the UserForm and clicks the Add button, the VBA code adds a new row to the Sales Data table. The Total column automatically calculates the total price. The form fields clear and focus resets for next entry.
Try adding a new sale with Product = "Pencil", Quantity = 8, Price = 1.2. What will be the new Sale ID and Total value in the table?
MyForm?UserFormName.Show.MyForm.Show matches the correct syntax. Others are invalid VBA commands.Private Sub CommandButton1_Click() TextBox1.Text = "Hello" Label1.Caption = TextBox1.Text End Sub
Label1 show after clicking the button?TextBox1.Text to "Hello" and then sets Label1.Caption to the same text.Label1.Caption is assigned the value of TextBox1.Text, it will show "Hello".InputBox1 when a button is clicked:Private Sub ClearButton_Click() InputBox1.Text = Null End Sub
Text property expects a string, but Null is a special VBA value not valid here.Null.TextBox1 and TextBox2) and show the result in a Label (LabelResult) when a button is clicked. Which VBA code correctly does this?CInt() converts text to integers, allowing numeric addition.Pass the test and this pattern moves unknown