How to Add Excel VBA UserForm Data to the Correct Product Section
Question details
The user needs to collect various data points via an Excel UserForm and write each submission to the first available row within a specific worksheet section that matches the selected product.
- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating data entry through a VBA UserForm where submissions must be categorized dynamically into designated product sections on a worksheet.
- Observed behavior
- Data submitted from the UserForm needs to be accurately routed to the correct product section and written to the next empty row.
Ensure your Developer tab is enabled and that you have backed up your workbook data before writing or testing new VBA macros.
Use the VBA Find Method to Locate and Populate the Section
Use the VBA Find function to locate the exact product name in the worksheet, determine the next available row in that section, and write the UserForm data.
By utilizing the Find method with an exact match, VBA can accurately locate the section header for the selected product. Once found, you can calculate the offset to identify the first empty row for data insertion.
Press ALT + F11 to open the Visual Basic for Applications (VBA) Editor and double-click your UserForm to view its code.
Set up variables for your target worksheet, the found cell, and the destination row number.
Use the Find method to search for the product name in your designated column. For example: Set cell = wsh.Columns("A").Find(What:=prodName, LookIn:=xlValues, LookAt:=xlWhole)
Calculate the first available row relative to the found cell. For instance, if your data starts two rows below the header, use: rowNum = cell.Row + 2.
Write the UserForm field values (such as item, work order, lot, pouch, basket, and expiration) to the required columns of the calculated destination row.
Easily Manage Macros and UserForms with WPS Spreadsheet
WPS Spreadsheet fully supports VBA macros, allowing you to create, edit, and execute UserForms natively. It is a highly compatible solution for automating your data entry tasks without compromising functionality.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open your macro-enabled workbook containing the UserForm.
- 2. Access the Developer Tab: Navigate to the 'Developer' tab located on the top ribbon menu.
- 3. Open the VBA Editor: Click on 'VBA Editor' to access your code, adjust the Find method parameters, and seamlessly test your UserForm functionality.

Frequently Asked Questions
Why is the VBA Find method returning a 'Object variable not set' error?
This usually happens if the target product name cannot be found in the specified search range. Ensure you add an error-handling statement like 'If Not cell Is Nothing Then' before attempting to extract the row number.
How do I dynamically find the first empty row within a specific section?
Once you locate the section header using the Find method, you can use the End(xlDown) property or a Do While loop to iterate downward until an empty cell is encountered, establishing your target insertion row.
Can I use INDIRECT formulas instead of VBA to route data?
While formulas like SUM(INDIRECT(...)) can dynamically reference ranges for calculations, they cannot actively push or write new data submitted from a UserForm into specific cells. VBA is strictly required for routing and inserting form submissions.




