
π This article includes 2 downloadable practice files β
When several people type into the same sheet, rows get skipped, dates get typed as text and names get misspelt. A UserForm gives them a clean form with drop-downs and checks, and writes each entry into a Table in the right format.
In this article
1. The table
On a sheet called Entries, create a Table (Ctrl+T) named tblEntries with columns Date, Customer, Region, Amount, EnteredBy. Keep drop-down lists (Regions, Customers) on a Lists sheet.
2. Design the form
Alt+F11 βΊ Insert βΊ UserForm. From the Toolbox add labels and: txtDate (TextBox), cboCustomer and cboRegion (ComboBox), txtAmount (TextBox), cmdSave and cmdClose (CommandButton). Set each control’s Name in the Properties window.
3. Fill drop-downs when the form opens
Private Sub UserForm_Initialize()
cboRegion.List = Application.Transpose(Sheets("Lists").Range("A2:A5").Value)
cboCustomer.List = Application.Transpose(Sheets("Lists").Range("C2:C50").Value)
txtDate.Value = Format(Date, "dd-mm-yyyy")
End Sub
4. Validate and save
Private Sub cmdSave_Click()
If Not IsDate(txtDate.Value) Then MsgBox "Enter a valid date": txtDate.SetFocus: Exit Sub
If cboCustomer.ListIndex = -1 Then MsgBox "Pick a customer from the list": Exit Sub
If Not IsNumeric(txtAmount.Value) Or Val(txtAmount.Value) <= 0 Then MsgBox "Amount must be a positive number": Exit Sub
Dim r As ListRow
Set r = Sheets("Entries").ListObjects("tblEntries").ListRows.Add
r.Range.Value = Array(CDate(txtDate.Value), cboCustomer.Value, cboRegion.Value, CDbl(txtAmount.Value), Environ("Username"))
txtAmount.Value = "": txtAmount.SetFocus ' ready for the next entry
End Sub
Private Sub cmdClose_Click(): Unload Me: End Sub
5. Open it from a button
In a normal module: Sub ShowForm(): frmEntry.Show: End Sub, then Insert βΊ Shapes on the sheet, right-click βΊ Assign Macro. Save as .xlsm (or .xlsb).
Where people go wrong
| Problem | Fix |
|---|---|
| Dates stored as text | Convert with CDate before writing |
| Amounts as text | CDbl before writing |
| Rows overwrite each other | Use ListRows.Add, not a fixed row number |
Full course: Excel VBA course, lesson 15 on UserForms.
Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.
π Practice files for this article
β¬ Download all 2 files (ZIP Β· 7 KB)
- πData-entry starter workbookAn Entries table, dropdown lists and step-by-step setup for the UserForm.β¬ XLSX Β· 7 KB
- πuserform-code.txtComplete UserForm code with input validation that adds rows to the table.β¬ TXT Β· 1 KB
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time β plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul βStuck on a step? Ask a question and the AI answers using this article.