Excel VBA UserForm Data Entry: Step-by-Step Guide

Build an Excel VBA UserForm for data entry step by step: design the form, validate inputs, save each record to a table and clear for the next.

Excel VBA UserForm for Data Entry: Step-by-Step Guide

Typing straight into a spreadsheet works until several people share the file. Then you get dates typed as text, misspelled categories and someone overwriting row 200 by accident. An Excel VBA UserForm data entry screen fixes that by giving users a clean form with labeled boxes, dropdowns and checks, while the macro writes each record safely to the bottom of a table. In this step-by-step guide you will design the form, validate every field, save records to an Excel Table and reset the form for the next entry.

The example is a simple sales log, but the same pattern works for customer lists, expense claims, inventory movements or service tickets. I use a version of this code in many client workbooks because it is short, easy to maintain and hard for users to break.

Step 1: Prepare the data table

Always save form entries into an Excel Table, not a plain range. Tables grow automatically, keep formatting consistent and let your code refer to columns by name instead of by letter.

  1. Add a sheet named Data.
  2. In A1:F1 type these headers: Date, Customer, Email, Phone, Category, Amount.
  3. Select A1:F2 and press Ctrl+T, tick My table has headers, and click OK.
  4. On the Table Design tab, rename the table to tblEntries.
  5. Right click the empty row 2 and choose Delete, Table Rows, so the table starts with zero data rows.
  6. Format the Phone column as Text so leading zeros are kept, and the Date column with a date format you like.
  7. Save the workbook as Excel Macro-Enabled Workbook (.xlsm).

Step 2: Design the UserForm

Press Alt+F11 to open the Visual Basic Editor. Choose Insert, UserForm. Press F4 to show the Properties window and set the form’s (Name) to frmEntry and its Caption to “New Sale”.

From the Toolbox, draw a Label and a control for each field, then name each control in the Properties window. Clear names make the code readable, so use a short prefix for the control type:

Field Control (Name)
Date TextBox txtDate
Customer TextBox txtCustomer
Email TextBox txtEmail
Phone TextBox txtPhone
Category ComboBox cboCategory
Amount TextBox txtAmount
Save button CommandButton cmdSave
Clear button CommandButton cmdClear
Close button CommandButton cmdClose
Status message Label lblStatus

Two small settings make the form feel professional. Set Default to True on cmdSave, so pressing Enter saves the record, and Cancel to True on cmdClose, so Esc closes the form. Then right click the form, choose Tab Order and arrange the controls top to bottom so users can tab through fields in a natural order.

Step 3: Write the form code with validation

Double click the form to open its code window, delete anything already there and paste the code below. It fills the dropdown, checks every field, writes the record to the table and clears the form.

Option Explicit

Private Const DataSheetName As String = "Data"
Private Const TableName As String = "tblEntries"

Private Sub UserForm_Initialize()
    With Me.cboCategory
        .List = Array("Retail", "Wholesale", "Online", "Other")
        .Style = fmStyleDropDownList      ' users can only pick from the list
    End With
    ClearForm
End Sub

' Reset all fields for the next entry
Private Sub ClearForm()
    Me.txtDate.Value = Format(Date, "dd-mmm-yyyy")
    Me.txtCustomer.Value = ""
    Me.txtEmail.Value = ""
    Me.txtPhone.Value = ""
    Me.cboCategory.ListIndex = -1
    Me.txtAmount.Value = ""
End Sub

' Show a message and put the cursor in the field that needs fixing
Private Sub ShowProblem(Message As String, Ctrl As Object)
    MsgBox Message, vbExclamation, "Please check this entry"
    Ctrl.SetFocus
End Sub

Private Function IsValidEntry() As Boolean
    If Not IsDate(Me.txtDate.Value) Then
        ShowProblem "Enter a valid date, for example 05-Nov-2026.", Me.txtDate
        Exit Function
    End If
    If Len(Trim$(Me.txtCustomer.Value)) = 0 Then
        ShowProblem "Customer name is required.", Me.txtCustomer
        Exit Function
    End If
    If Len(Me.txtEmail.Value) > 0 And Not Me.txtEmail.Value Like "*@*.*" Then
        ShowProblem "That email address does not look right.", Me.txtEmail
        Exit Function
    End If
    If Me.cboCategory.ListIndex = -1 Then
        ShowProblem "Please choose a category.", Me.cboCategory
        Exit Function
    End If
    If Not IsNumeric(Me.txtAmount.Value) Then
        ShowProblem "Amount must be a number.", Me.txtAmount
        Exit Function
    End If
    IsValidEntry = True
End Function

' Write one value into the new row, finding the column by its header
Private Sub WriteField(Tbl As ListObject, RowRange As Range, _
                      ColumnName As String, FieldValue As Variant)
    RowRange.Cells(1, Tbl.ListColumns(ColumnName).Index).Value = FieldValue
End Sub

Private Sub cmdSave_Click()
    Dim Tbl As ListObject
    Dim NewRow As ListRow

    If Not IsValidEntry Then Exit Sub

    Set Tbl = ThisWorkbook.Worksheets(DataSheetName).ListObjects(TableName)
    Set NewRow = Tbl.ListRows.Add          ' new empty row at the bottom

    WriteField Tbl, NewRow.Range, "Date", CDate(Me.txtDate.Value)
    WriteField Tbl, NewRow.Range, "Customer", Trim$(Me.txtCustomer.Value)
    WriteField Tbl, NewRow.Range, "Email", Trim$(Me.txtEmail.Value)
    WriteField Tbl, NewRow.Range, "Phone", Trim$(Me.txtPhone.Value)
    WriteField Tbl, NewRow.Range, "Category", Me.cboCategory.Value
    WriteField Tbl, NewRow.Range, "Amount", CDbl(Me.txtAmount.Value)

    Me.lblStatus.Caption = "Saved. Records in table: " & Tbl.ListRows.Count
    ClearForm
    Me.txtCustomer.SetFocus
End Sub

Private Sub cmdClear_Click()
    ClearForm
    Me.lblStatus.Caption = ""
    Me.txtCustomer.SetFocus
End Sub

Private Sub cmdClose_Click()
    Unload Me
End Sub

A few design choices worth explaining. The date is shown as dd-mmm-yyyy (for example 05-Nov-2026) because a month name cannot be misread, while 05/11/2026 means May in the US and November in the UK. Writing values by column name means you can reorder or add columns in the table later without touching the code. And the form stays open after saving, which is what people entering a stack of records actually want.

Optional: warn about duplicates

If each customer email should appear once, add this function to the form and call it in cmdSave_Click right after the table is set. Note the check for an empty table: when a table has no data rows, its DataBodyRange is Nothing and COUNTIF would raise an error.

Private Function IsDuplicate(Tbl As ListObject, EmailText As String) As Boolean
    If Tbl.ListRows.Count = 0 Or Len(EmailText) = 0 Then Exit Function
    IsDuplicate = Application.WorksheetFunction.CountIf( _
        Tbl.ListColumns("Email").DataBodyRange, EmailText) > 0
End Function

' In cmdSave_Click, after Set Tbl = ...
If IsDuplicate(Tbl, Trim$(Me.txtEmail.Value)) Then
    If MsgBox("This email already exists. Save anyway?", _
              vbYesNo + vbQuestion) = vbNo Then Exit Sub
End If

Step 4: Add a button to open the form

  1. In the Visual Basic Editor choose Insert, Module and paste the macro below.
  2. Back in Excel, go to Developer, Insert, Button (Form Control) and draw a button on an Entry or Home sheet.
  3. When asked, assign the OpenEntryForm macro and rename the button to “Add New Sale”.
Sub OpenEntryForm()
    frmEntry.Show            ' use frmEntry.Show vbModeless to allow clicking the sheet
End Sub

If you do not see the Developer tab, enable it under File, Options, Customize Ribbon. Test the form with good and bad values: an empty customer, letters in the amount, a date like 31-Feb-2026. Each should be caught with a clear message.

Common mistakes with data entry UserForms

  • Finding the last row with a hard-coded range. Code like Range("A1000").End(xlUp) breaks as the data grows. ListRows.Add always lands in the right place.
  • Saving numbers as text. A TextBox value is always text. Convert with CDbl or CDate before writing, or totals and filters will misbehave.
  • Protected data sheet. ListRows.Add fails on a protected sheet. Unprotect in code before saving and protect again afterward, as shown in my guide to locking and unlocking sheets with VBA.
  • Leaving the blank starter row in the table. New tables often include one empty row, and your first record ends up below it.
  • Saving as .xlsx. Excel strips all macros and the form silently disappears.

Frequently asked questions

Can a UserForm edit existing records too?

Yes. Add a search box that finds the row with Range.Find or MATCH, load the values into the controls, and write them back to the same ListRow instead of adding a new one.

Will this work on Excel for Mac?

Yes, UserForms run in Excel for Mac. The Mac editor is less comfortable for designing forms, so many developers lay out the form on Windows, but the code above runs on both.

Can several people enter data at the same time?

Not reliably in one shared .xlsm file, because macros do not run in Excel for the web and co-authoring does not support them. For multiple users, consider a shared database or a Google Sheets form with Apps Script.

Want a custom data entry system?

A form like this is often the first piece of a bigger tool, such as the invoice generator and database in my portfolio. If you need one built around your own process, see my Excel VBA automation service or get an instant quote.

12 Excel VBA macros that save hours every week

The small macros I use on almost every client file. One .bas file you import once, with clear comments and step by step instructions.

  • Unhide, protect and unprotect all sheets
  • Delete blank rows and clean messy text
  • Highlight duplicates in any range
  • Split one sheet into many by a column
  • Combine every sheet into one
  • Export each sheet to its own PDF
  • Clickable sheet index, dated backups and a formula audit list

No spam. Your email is never shared. Privacy Policy

Sourab Saha, Data Analyst

About the author

Sourab Saha · Data Analyst · Kolkata, India

I’m Sourab Saha, a data analyst and automation developer from Kolkata, India, with more than ten years of experience turning manual data work into clean, automated systems. On Fiverr and Upwork I have delivered over 500 data and automation projects for clients in the US, UK, Europe, Australia and the Middle East, with a 5.0 rating on both platforms. My toolkit is Excel VBA, SQL, Power BI and DAX, Python with Selenium, and Google Apps Script. I collect data from files, databases and websites, clean it, model it and present it so decisions take minutes instead of days. I build and test every tool on your real data, deliver it with a short walkthrough, and keep revising until it works exactly the way you need. Alongside my freelance work, since 2024 I have also worked as a Data Analyst for AH Group of Industries, a US healthcare group, building automated reports and Power BI dashboards from billing, payroll, audit and attendance data.

Rated 5.0 on Fiverr and Upwork, with more than 500 automation projects delivered and over ten years of Excel VBA. You get a fixed price before any work starts, your files stay private on your order page, and every order comes with a proper invoice.

WhatsApp