How to Use VBA TextBox to Enter Data in Column A Starting at Cell A2
Question details
The user needs to write data from a VBA UserForm TextBox into the next available row in an Excel spreadsheet's column A, ensuring the first entry always starts at cell A2.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating an automated data entry form using a UserForm Command Button to populate a specific column sequentially while preserving the column header.
- Observed behavior
- The first submitted value must be placed exactly in cell A2, and each subsequent click of the command button should populate the next available empty row (A3, A4, etc.) without overwriting existing data.
Ensure that the Developer tab is enabled in your spreadsheet application and that macros are permitted to run so you can access and test the VBA Editor.
Use the End(xlUp) Method to Find the Next Empty Row
This is the most reliable method. It searches from the bottom of the worksheet upwards to find the last used row, ensuring no data is accidentally overwritten.
By utilizing the `.End(xlUp)` property, the script dynamically calculates the next empty row. Adding a conditional check guarantees that the data entry will never overwrite row 1, keeping your headers safe.
Press ALT + F11 to open the Visual Basic for Applications (VBA) editor, and double-click your UserForm to view its code.
Double-click the Command Button on your UserForm to automatically generate the 'CommandButton1_Click' event subroutine.
Paste the following code inside the subroutine: Dim emptyRow As Long With Sheet1 emptyRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 If emptyRow < 2 Then emptyRow = 2 .Cells(emptyRow, 1).Value = TextBox1.Value End With
To automatically clear the TextBox for the next entry, add 'TextBox1.Value = ""' right before 'End Sub'.

Use the WorksheetFunction.CountA Method
An alternative approach that counts the number of non-empty cells in the column to determine the next available row.
Execute VBA UserForms and Macros Effortlessly in WPS Office
WPS Spreadsheet offers powerful built-in support for VBA macros. You can create UserForms, automate repetitive data entry, and run custom scripts just as you would in Microsoft Excel, completely free of charge.
- 1. Enable Developer Tools: Open WPS Spreadsheet, go to the Options menu, and ensure the Developer tab is enabled.
- 2. Launch the VBA Editor: Click on the Developer tab and select 'VBA Editor' to open the macro programming environment.
- 3. Create Your UserForm: Insert a new UserForm, drag and drop a TextBox and a CommandButton onto the canvas from the toolbox.
- 4. Run Your Code: Double-click the button, paste your dynamic row-finding code, and run the form to start entering data directly into cell A2.

Frequently Asked Questions
Why does my VBA code overwrite the header in cell A1?
This occurs if the code identifies row 1 as the next empty row when the sheet is entirely blank. Adding the conditional statement 'If emptyRow < 2 Then emptyRow = 2' forces the script to bypass row 1 and start at row 2.
How do I clear the TextBox after clicking the command button?
You can automatically reset the text field by adding the line 'TextBox1.Value = ""' at the very end of your CommandButton_Click event code, right before 'End Sub'.
Can I adapt this code to enter data into column B instead?
Yes. To target column B, change the column letter in '.Cells(.Rows.Count, "A")' to '"B"', and change the column index in '.Cells(emptyRow, 1)' to '.Cells(emptyRow, 2)'.
What happens if there are blank rows in my existing data?
If you use the 'End(xlUp)' method, it will safely find the true last row regardless of gaps. However, if you use the 'CountA' method, blank rows will result in a lower count, causing the script to overwrite existing data.




