🎉 Black Friday Sale: 40% OFF everything with code BF40 · ends 1 Dec  Shop now →

Excel VBA UserForm Tutorial: Build a Data Entry App in One Afternoon

This excel vba userform tutorial builds a working order entry app in one afternoon. You create a table named tblOrders, a form called frmOrder, and two short blocks of VBA that validate input and save each order as a new row with an automatic ID, date and total. You type no formulas into the sheet.

Last updated: November 2026

Key takeaways

  • The build needs one .xlsm workbook, one sheet named Data, one table named tblOrders (7 columns, A1:G1) and one UserForm named frmOrder.
  • Validation sits in a function called ValidateOrder, so the form only displays the message it returns and the rules live in one place.
  • SaveOrder handles an empty table, so the first order always gets ID 1 and no blank row is left above your data.
  • In our test run on 26 November 2026, an order of 3 units at 19.99 saved as order 1 with a Total of 59.97.
  • If you would rather not build it, the Data Entry Form in Excel is a ready-made VBA tool for $6.99.
Excel VBA Advanced with AI courseLaunch offer
🎓 NEXTGENTEMPLATES ACADEMY
Want to build VBA systems like these yourself?
Excel VBA Advanced with AI

Arrays, dictionaries, UserForms, events, class modules, error handling and file/folder automation, with AI as your pair programmer. 6h 28m of video across 14 modules, with practice and solution files for every lesson.

What does this excel vba userform tutorial build?

The project is a small order entry app. A user opens a form, types a customer name, picks a product from a drop-down, enters a quantity and a unit price, and presses Save. The code checks the input, writes one row to a table and reports the result in a status label.

An excel vba userform like this is the usual first step from typing into cells to a proper vba data entry form. People enter data through controls you chose, so they cannot overwrite a formula, skip a column or type text where a number belongs.

The finished app has three parts:

  • A table. tblOrders on a sheet called Data, with the columns ID, Date, Customer, Product, Qty, Price and Total.
  • A module. modOrders holds three procedures: one to open the form, one to validate input and one to save a row.
  • A form. frmOrder holds the controls and the code that connects the buttons to the module.

All the code is given in full below. Paste it exactly as shown, because the steps and the test results refer to these names. If you have never written a macro, the Excel macros for beginners guide covers the basics of recording and running one.

What do you need before you start?

You need desktop Excel for Windows, since the build uses the VBA editor. Excel for the web does not run VBA. You also need to be allowed to run macros on your machine. Some company IT policies block them, and if yours does, ask before you spend the afternoon.

No add-ins are needed. Plan on about 90 minutes if you follow every step, plus time to test. The test table later in this post lists the exact inputs we ran and the exact messages Excel returned.

Step 1: How do you set up the workbook and the tblOrders table?

  1. Open a new workbook and save it straight away as an Excel Macro-Enabled Workbook (.xlsm). A plain .xlsx file cannot store VBA, so doing this first means you never lose the code.
  2. Rename the first sheet to Data. The code looks for this exact name.
  3. In cells A1 to G1, type the headers: ID, Date, Customer, Product, Qty, Price, Total.
  4. Click any header cell, then choose Insert > Table. Tick "My table has headers" and confirm.
  5. With the table selected, open the Table Design tab and set the Table Name box to tblOrders.

The table name matters more than anything else in this step. The save routine finds the table with ListObjects("tblOrders"), so a typo here produces a subscript error the first time you press Save.

Using a table instead of a plain range has a practical benefit. A table grows when you add a row, so the code never has to calculate the last used row. It also gives each column a name, which the save routine uses to find the highest ID.

Shortcut: if you want a finished entry sheet instead of building one, the Smart Data Entry Form with Minimum VBA ($6.99) is described as a ready-made form with customizable fields, built-in data validation and automatic date stamping.

Step 2: How do you add the module and the UserForm?

  1. Press Alt+F11 to open the VBA editor.
  2. Choose Insert > Module. In the Properties window (press F4 if it is hidden) change the Name from Module1 to modOrders.
  3. Choose Insert > UserForm. In the Properties window change its Name to frmOrder. You can also set its Caption to something friendly such as Order Entry.

Keeping code in two places is deliberate. The module holds logic that does not care about the screen: checking text and writing to a table. The form holds only what belongs to the screen: reading controls, showing messages and clearing boxes. When logic and display are kept apart, you can change one without breaking the other.

Both pieces of code start with Option Explicit. That line forces you to declare every variable, so a misspelled name raises an error when you compile instead of silently creating an empty variable. Turn on Tools > Options > Require Variable Declaration if you want the editor to add it for you on new modules.

Step 3: Which controls go on the form?

With frmOrder open, the Toolbox appears. Drag the controls onto the form and set the Name property of each one in the Properties window. The code refers to these names exactly, so spelling counts.

ControlNameSettingPurpose
TextBoxtxtCustomerDefaultCustomer name
ComboBoxcboProductStyle = 2 (fmStyleDropDownList)Pick one product, no free typing
TextBoxtxtQtyDefaultQuantity
TextBoxtxtPriceDefaultUnit price
CommandButtoncmdSaveCaption = SaveValidate and save the order
CommandButtoncmdCloseCaption = CloseClose the form
LabellblStatusEmpty captionShows errors and the save message
Labels (x4)AnyCaptions: Customer, Product, Quantity, Unit priceTell the user what each box is for

Set the ComboBox Style to 2 before anything else. The default style lets a user type any text into the box, which defeats the point of a list. With style 2 the user can only choose one of the items you load, so the Product column stays consistent. The Excel drop down list guide covers the same idea on the worksheet side.

Layout is up to you. A sensible order is Customer, Product, Quantity, Unit price from top to bottom, then the two buttons, then the status label at the bottom where the eye lands after pressing Save. Set the TabIndex of each control so that Tab moves in that same order. A form people can fill without touching the mouse is much faster to use all day.

The Total column has no control. The code calculates it from quantity and price, so nobody can enter a wrong total by hand.

Step 4: What goes in the modOrders module?

Double-click modOrders in the Project window and paste the following. It contains all three procedures. The next sections explain each one.

Option Explicit

Public Sub ShowOrderForm()
    frmOrder.Show
End Sub

Public Function ValidateOrder(ByVal customer As String, ByVal qtyText As String, _
                              ByVal priceText As String) As String
    If Len(Trim$(customer)) = 0 Then
        ValidateOrder = "Enter a customer name."
    ElseIf Not IsNumeric(qtyText) Then
        ValidateOrder = "Quantity must be a number."
    ElseIf CDbl(qtyText) <= 0 Or CDbl(qtyText) <> Int(CDbl(qtyText)) Then
        ValidateOrder = "Quantity must be a whole number above zero."
    ElseIf Not IsNumeric(priceText) Then
        ValidateOrder = "Unit price must be a number."
    ElseIf CDbl(priceText) < 0 Then
        ValidateOrder = "Unit price cannot be negative."
    End If
End Function

Public Function SaveOrder(ByVal customer As String, ByVal product As String, _
                          ByVal qty As Long, ByVal price As Double) As Long
    Dim tbl As ListObject, target As Range, nextId As Long

    Set tbl = ThisWorkbook.Worksheets("Data").ListObjects("tblOrders")

    If tbl.ListRows.Count = 0 Then
        nextId = 1
        Set target = tbl.ListRows.Add.Range
    ElseIf Application.WorksheetFunction.CountA(tbl.DataBodyRange) = 0 Then
        nextId = 1
        Set target = tbl.ListRows(1).Range
    Else
        nextId = Application.WorksheetFunction.Max(tbl.ListColumns("ID").DataBodyRange) + 1
        Set target = tbl.ListRows.Add.Range
    End If

    target.Value = Array(nextId, Date, customer, product, qty, price, qty * price)
    SaveOrder = nextId
End Function

ShowOrderForm: the opener

ShowOrderForm has one job: it shows frmOrder. It exists so you have a clean macro name to run or attach to a button on the sheet. Run it from Alt+F8, from the Macros button on the Developer tab, or by placing the cursor inside it in the editor and pressing F5.

ValidateOrder: why validation sits in a function

ValidateOrder takes the three text values from the form and returns a string. If everything is fine it returns an empty string. If something is wrong it returns the message to show the user.

Putting this in a function, instead of inside the button code, has three benefits:

  • One place for the rules. If your rule for quantity changes, you edit one line and every form that calls the function follows.
  • A short button handler. The Save button only asks "is there a message?" and does not need to know what a valid quantity is.
  • It can be tested alone. You can call the function from the Immediate window with sample text and read the result without opening the form.

The checks run in order, and the first failure wins. A blank customer is caught first, using Trim$ so a name made only of spaces counts as blank. Then the quantity is tested with IsNumeric. After that comes the whole-number rule: the quantity must be above zero, and it must equal its own Int value, which rejects 2.5. The unit price is checked next, first for being numeric and then for not being negative. A price of zero passes, which is useful for free samples.

Notice that the function receives qtyText and priceText as strings. A TextBox always hands back text, so the function converts to numbers only after IsNumeric has said the conversion is safe. Calling CDbl on the word abc would crash the macro, and the order of the checks prevents that.

SaveOrder: why it handles an empty table

SaveOrder receives clean, already-validated values and writes one row. It first gets a reference to tblOrders on the Data sheet, then chooses where the new row goes. There are three cases:

  1. The table has zero rows. This happens if someone deleted every row of the table. The code adds a row and sets the ID to 1.
  2. The table has rows but they are all empty. A table you have just created has one blank row. CountA counts non-empty cells in the data body, and when it returns 0 the code reuses that first row instead of adding a second. Without this branch, your first order would land in row 3 with an empty row above it.
  3. The table already has data. The code finds the highest value in the ID column, adds 1, and appends a row.

The final line writes all seven values in one go with Array(nextId, Date, customer, product, qty, price, qty * price). The order of the array matches the order of the columns: ID, Date, Customer, Product, Qty, Price, Total. Date is today’s date from the system clock. The function returns the new ID so the form can show it.

If you add or reorder columns in tblOrders later, remember that the array must change to match. A mismatch is the most common reason a saved row looks scrambled.

Shortcut: the Data Entry Application in Excel VBA ($6.99) is described as an Excel VBA application with automated validation, error checking and reporting, if you want those without coding them.

Step 5: What code goes behind the form?

Double-click frmOrder (or select it and press F7) to open its code window, then paste this block. It connects the buttons to the module.

Option Explicit

Private Sub UserForm_Initialize()
    cboProduct.List = Array("Dashboard", "Tracker", "Management System")
    cboProduct.ListIndex = 0
End Sub

Private Sub cmdSave_Click()
    Dim msg As String, newId As Long

    msg = ValidateOrder(txtCustomer.Value, txtQty.Value, txtPrice.Value)
    If Len(msg) > 0 Then
        lblStatus.Caption = msg
        Exit Sub
    End If

    newId = SaveOrder(Trim$(txtCustomer.Value), cboProduct.Value, _
                      CLng(txtQty.Value), CDbl(txtPrice.Value))
    ClearForm
    lblStatus.Caption = "Saved order " & newId & "."
End Sub

Private Sub cmdClose_Click()
    Unload Me
End Sub

Private Sub ClearForm()
    txtCustomer.Value = ""
    txtQty.Value = ""
    txtPrice.Value = ""
    txtCustomer.SetFocus
End Sub

UserForm_Initialize: filling the drop-down

Excel runs UserForm_Initialize once, just before the form appears. It loads three products into cboProduct and selects the first, so the box is never empty. Because the style is a drop-down list, the value is always one of the three entries. To change the products, edit the names inside the Array call.

cmdSave_Click: the main routine

When the user presses Save, the code asks ValidateOrder for a message. If the message has any length, it goes into lblStatus and the routine stops with Exit Sub. Nothing is written, and the typed values stay in the boxes so the user can fix them.

If the message is empty, the code calls SaveOrder. The customer name is trimmed, the quantity is converted with CLng and the price with CDbl. These conversions are safe because validation has already passed. The returned ID is kept in newId, the boxes are cleared, and the label reads "Saved order" followed by the number.

ClearForm and cmdClose_Click

ClearForm empties the three text boxes and puts the cursor back in the customer box, ready for the next order. Leaving cboProduct alone is intentional, since consecutive orders often share a product. cmdClose_Click unloads the form with Unload Me.

The status label does two jobs: it shows errors and it confirms the save. Because the confirmation is written after ClearForm, the user sees an empty form and a clear message, which is how they know it worked. A message box would also work, but each box needs a click, and a label does not slow a person entering fifty orders.

Shortcut: for a form that tracks something specific, the Training Enrollment Data Entry Form ($6.99) is described as a VBA-powered Excel form with drop-down lists, add and delete buttons and automatic timestamps.

Step 6: How do you test the excel vba userform?

Run ShowOrderForm and try each input below, one at a time. We ran this exact set in Excel on 26 November 2026. The table shows the input and the message the status label displayed.

InputStatus label result
Customer left blankEnter a customer name.
Quantity: abcQuantity must be a number.
Quantity: 2.5Quantity must be a whole number above zero.
Quantity: 0Quantity must be a whole number above zero.
Unit price: xUnit price must be a number.
Unit price: -1Unit price cannot be negative.
Asha Rao, quantity 3, price 19.99Saved order 1. (Total column shows 59.97)
Ben Cole, quantity 1, price 6.99Saved order 2.

The first two saves are the important ones. The Asha Rao order proves the empty-table branch: it landed in the first row with ID 1, and the Total of 59.97 equals 3 multiplied by 19.99. The Ben Cole order proves the third branch, because the code found the highest ID (1) and added one to give 2.

The 2.5 and 0 results share one message on purpose. Both break the same rule, a whole number above zero, so a single sentence covers them.

Test the failures first and the saves last. If you save before testing, you have to delete rows from the table afterwards, and clearing rows is the exact situation the empty-table branch exists for. To retest it, delete all rows of tblOrders and save again; the new order should get ID 1.

What are the common errors and how do you fix them?

SymptomLikely causeFix
Subscript out of range on SaveThe sheet is not named Data, or the table is not named tblOrdersRename the sheet and the table exactly as spelled in the code
Macros disappear after savingFile saved as .xlsxSave as Excel Macro-Enabled Workbook (.xlsm)
Compile error: variable not definedA control name is misspelled or missingCheck each Name property against the controls table above
Drop-down accepts typed textcboProduct Style is still the defaultSet Style to 2 (fmStyleDropDownList)
Row saved with values in the wrong columnsTable columns are in a different order than the arrayMatch the header order ID, Date, Customer, Product, Qty, Price, Total
Nothing happens when you press Alt+F8Macros are disabled by Excel security or IT policyEnable macros for this file, or ask your administrator
First order appears in the second rowThe SaveOrder empty-table branch was changed or removedRestore the block exactly as given
Save button does nothingThe button is not named cmdSave, so the click procedure is not attachedRename the button and check the procedure name matches

If the error is a runtime error and you want to see where it stopped, click Debug when the dialog appears. The editor highlights the failing line in yellow. Hovering over a variable shows its current value, which is usually enough to spot a wrong name or an empty string.

When is this build NOT the right answer?

This is a teaching build, and it has limits you should know before anyone depends on it.

  • A customer name beginning with = is read as a formula. Excel treats a value that starts with an equals sign as a formula when it is written to a cell. The code does not guard against this, so add a check if your customers could have such names.
  • Very large quantities overflow CLng. CLng converts to a Long integer, which has a fixed upper limit. A quantity beyond that limit raises an error instead of saving. Realistic order quantities are far below it, but the validator does not stop the case.
  • IsNumeric follows regional decimal settings. On a system that uses a comma as the decimal mark, 19.99 may be refused and 19,99 accepted. Test with the format your users will type.
  • It is not safe for several people at once. There is no locking. The next ID comes from the current maximum, so two people saving on a shared file could collide.

There is also a size question. A table in a workbook is fine for hundreds or a few thousand orders. If you need shared entry, user logins, an audit trail or reporting across departments, buy or build proper software instead. A database-backed order system, or a tool such as Airtable, handles concurrent users that a single .xlsm file cannot. The Airtable alternatives roundup covers tracker options in Excel and Sheets.

Finally, VBA is desktop-only. If your team works in a browser or on phones, a form built this way will not run for them.

How can you extend the form?

The structure leaves room to grow without rewriting what you have. These are ideas, described in words so you can apply them to your own copy:

  • Add more columns to tblOrders, such as a status or a delivery date, then add the matching controls and extend the array so it has one value per column.
  • Replace the three product names with your own list, or load them from a range on another sheet so staff can change the list without opening the editor.
  • Put a button on the Data sheet and assign ShowOrderForm to it, so users never see the VBA editor.
  • Protect the project with a password from Tools > VBAProject Properties, and lock the Data sheet so rows can only be added through the form.
  • Feed tblOrders into a report. The Power Pivot guide and the Power Query tutorial show how to turn a table like this into a one-click summary.

Official reference for the objects used here (ListObject, ListRows, Range and the UserForm controls) is in the Microsoft Excel VBA reference. It lists every property mentioned in this tutorial.

Once the order app works, the next step is usually edit, delete and search. The Excel data entry systems roundup lists eight VBA tools that include those functions, and the Excel VBA tools for small business post covers ten ready-made automations.

Which ready-made VBA data entry tools can save you the build?

Building is the best way to learn, but a ready-made form can be quicker when you only need the result. Here are three from the catalog, each at $6.99, with claims taken from their descriptions.

Data Entry Form in Excel ($6.99)

excel vba userform tutorial

This Data Entry Form in Excel is a VBA tool for collecting and managing data. Its description lists drop-down lists, pre-set fields, validation rules and a customizable layout. It suits anyone who wants a finished form with those features instead of building a vba data entry form from scratch.

Smart Data Entry Form with Minimum VBA ($6.99)

Smart data entry form with minimum VBA in Excel

The Smart Data Entry Form with Minimum VBA is built for small business owners, freelancers, HR teams and sales teams. It has built-in validation, automatic date stamping and entries saved to the worksheet. The date stamp is the same idea as the Date column in your own tblOrders.

Data Entry Application in Excel VBA ($6.99)

Data entry application in Excel VBA with validation

The Data Entry Application in Excel VBA is described as automating validation, error checking and reporting, with customizable inputs. It is the closest match if you want the order app plus reports.

For larger systems with logins and role-based access, the Offer Letter Management System ($19.99) and the HR Document Management System ($19.99) are both role-based Excel VBA applications with Admin and User logins. They are HR tools, not order entry, so choose them only if that is your use. See Excel VBA systems for more of this type.

To keep the form from crashing on bad input, add error handling with our VBA try catch and debugging guide.

Frequently asked questions

What is an Excel VBA UserForm?

An Excel VBA UserForm is a custom dialog window you design in the VBA editor with text boxes, drop-downs and buttons. Users type into the controls instead of worksheet cells, and your code checks the input and writes it to a sheet. It gives you a controlled vba data entry form inside a normal workbook.

How do I open the VBA editor in Excel?

Press Alt+F11 in Excel to open the VBA editor. If nothing happens, check that you are in desktop Excel, since Excel for the web does not run VBA. From the editor you can insert modules and UserForms from the Insert menu and open form code with F7 or a double-click.

Why must the workbook be saved as .xlsm?

A standard .xlsx file cannot store macros, so Excel strips the VBA when you save in that format. Saving as .xlsm, the macro-enabled workbook, keeps the module and the form. Save as .xlsm before you write any code so you never lose the work. Before you share the file, see how to lock cells in Excel and protect the sheets around your form.

How do I make the ComboBox accept only listed items?

Set the Style property of cboProduct to 2 (fmStyleDropDownList) in the Properties window. The user can then only pick from the list and cannot type a free value. The list itself is filled in the UserForm_Initialize routine, using the three products in the Array call.

Why does validation sit in a function?

A function returns a message that any caller can read, so the form only has to display it. The rules live in one place, which makes them easy to change or reuse, and the button code stays short. An empty result means the input passed every check.

What happens if the table is empty?

SaveOrder checks the table first. If it has no rows, it adds one. If it has one blank row, as a new table does, it fills that row instead of adding another. Either way the first order gets ID 1, so you never get a blank row above your data.

Can several people use the form at once?

No. The code has no locking, and it works out the next ID by reading the current maximum. Two people saving at the same moment on a shared file could clash or overwrite each other. Treat this build as a single-user tool, or use a database for shared entry.

Why does my decimal price fail validation?

IsNumeric follows your computer’s regional settings. On a system that uses a comma as the decimal separator, 19.99 may be rejected and 19,99 accepted. Test with the format your users will actually type, and tell them which separator to use.

Can a customer name start with an equals sign?

Avoid it. Excel reads a value beginning with = as a formula when it is written to a cell, so the cell shows a result or an error instead of the text. The build does not guard against this, so add a check if your data may include such names.

Do I need to buy a template instead of building this?

No. This tutorial gives you a working order entry form to build yourself. A ready-made VBA tool makes sense when you want features such as validation rules and customizable fields without writing them. The Data Entry Form in Excel costs $6.99.

Get more VBA data entry tools

If you would rather start from a finished tool, the Data Entry Form in Excel is $6.99 and the Smart Data Entry Form with Minimum VBA is $6.99. For HR workflows with logins, the HR Document Management System is $19.99.

Watch walkthroughs and Excel tutorials on the NextGen Templates YouTube channel.

🎓 Learn to build this yourself. Excel VBA Advanced with AI · $69 one-timeStart the course →
Scroll to Top