VBA & Macro Problems

Fix Excel VBA Writing Form Data to the Same Row

Anum MushtaqAnum Mushtaq Nov 25, 2026 869 views

Question details

The user needs an Excel VBA data-entry form to save each submission to the next available row.

Fix Excel VBA Writing Form Data to the Same Row
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA form calculates a destination row and writes form values to a worksheet.
Observed behavior
The macro repeatedly writes to row 2 and checks a column that does not reliably contain the submitted data.
Before you start

Identify the destination worksheet and a column that is populated for every submitted record. Check the form's control names and confirm that the chosen column does not contain formulas or other content below the data table.

Solution 1Recommended

Use the calculated row and check a populated column

Use this approach when form submissions overwrite row 2 or the row calculation checks an empty column.

The example assumes the worksheet is named Roster, column D has a header in row 1, and TextBox1 supplies a value for column D on every submission. Change the sheet name, column number, and control names to match your form.

1
Open the form code

In Excel, open the workbook, press Alt+F11 to open the VBA editor, and open the code for the form's submit button.

2
Calculate and use the next row

Update the button's Click procedure to reference the correct sheet, check column D, and use iRow in each destination cell. For example: Private Sub CommandButton1_Click() Dim iRow As Long Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("Roster") If Trim(Me.TextBox1.Value) = "" Then MsgBox "Enter a value in TextBox1." Exit Sub End If With ws iRow = .Cells(.Rows.Count, 4).End(xlUp).Row + 1 .Cells(iRow, 4).Value = Me.TextBox1.Value .Cells(iRow, 5).Value = Me.TextBox3.Value .Cells(iRow, 6).Value = Me.TextBox4.Value End With End Sub

3
Update remaining fields

In the same Click procedure, change every remaining destination such as .Cells(2, 7) to .Cells(iRow, 7). Verify each Me.TextBox name against the form's control names.

4
Test multiple submissions

Run the form and submit two test records with TextBox1 populated. Open the Roster worksheet and confirm that the records appear on consecutive rows without overwriting each other.

Use the calculated row and check a populated column
Choose the lookup column carefully: If another column is populated for every record, replace 4 in the iRow calculation with that column's number. Formulas or other content below the table can cause the calculated row to be farther down than expected.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheets. Its Microsoft Office format compatibility helps you move everyday workbook tasks to WPS, though it does not fix Excel VBA code.

Open and edit Microsoft Excel XLSX and XLS filesEnter and organize spreadsheet records in WPS SpreadsheetsUse a familiar spreadsheet interface for everyday tasksMove compatible Office documents between applications
microsoft office alternative - wps office

Frequently Asked Questions

Why does my VBA form keep overwriting row 2?

The write statements may still use a hard-coded row, such as .Cells(2, 4). In the form's Click procedure, use .Cells(iRow, 4) and apply iRow to every destination cell.

Which column should I use to find the next row?

Use a column that contains a value for every record. For column D, use .Cells(.Rows.Count, 4).End(xlUp).Row + 1 inside a With block for the destination worksheet.

Why is the next row calculated far below my data?

The lookup column may contain formulas or other content below the table. Inspect that column in the destination worksheet and choose a reliably populated column without content extending below the records.

How do I check whether a text box name is correct?

In the VBA editor, open the UserForm, select the text box, and check its Name property in the Properties window. Use that exact name in the button's Click procedure.