VBA & Macro Problems

Write Excel UserForm Data to Specific Cells with VBA

Adam DavisAdam Davis Nov 18, 2026 868 views

Question details

Transfer values from Excel UserForm text boxes to fixed cells on a selected worksheet.

Write Excel UserForm Data to Specific Cells with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
Multiple worksheets share the same layout, and a UserForm should write values to specific cells on the chosen sheet.
Observed behavior
The desired result is for each text box value to appear in its designated cell on the selected worksheet.
Before you start

Check the target worksheet name and the names of the UserForm controls in the VBA editor. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the file.

Solution 1Recommended

Write UserForm values with row-first Cells references

Use this approach when each worksheet has the same cell layout and the form must write to a specific sheet.

The Cells property uses Cells(row, column), so D3 is Cells(3, 4), not Cells(4, 3). Qualifying Cells with a worksheet prevents the value from being written to whichever sheet happens to be active.

1
Open the UserForm code

In Excel, open the Developer tab and select Visual Basic. In Project Explorer, open your UserForm and double-click its submit button to open the button's Click event.

2
Write the value to D3

In the button's Click event, use a worksheet name and the text box name, for example: Private Sub CommandButton1_Click() Dim selectedSheet As String selectedSheet = "Sheet1" ThisWorkbook.Worksheets(selectedSheet).Cells(3, 4).Value = Me.FN.Value End Sub Replace Sheet1 with the target worksheet name or assign selectedSheet from your sheet selector. Replace FN with the name of your text box.

3
Add the remaining cells

Add another assignment inside the same Click event for each text box. Use Cells(4, 4) for D4, Cells(5, 4) for D5, Cells(3, 6) for F3, Cells(4, 6) for F4, and Cells(5, 6) for F5. Replace Me.FN with the appropriate control name in each assignment.

4
Run and check the form

Run the UserForm, enter a test value, and click its submit button. Open the selected worksheet and confirm that the value appears in D3 and the other designated cells.

Write UserForm values with row-first Cells references
Check the workbook reference: ThisWorkbook refers to the workbook containing the VBA code. If the target sheets are in another workbook, replace ThisWorkbook with an explicit reference to that open workbook.
Free Microsoft Office alternative

Work with spreadsheet files in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheet files. Its Microsoft Office format support can help you move everyday workbook work across applications, though it does not fix Excel VBA UserForm code and macro compatibility may vary.

Open and edit Microsoft Excel XLS and XLSX files.Work with worksheets and cell data in a familiar spreadsheet interface.Use a free, lightweight Office suite for everyday document work.Move common Office files between applications without starting from scratch.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Cells(4, 3) write to C4 instead of D3?

Cells takes the row number first and the column number second. Row 4 and column 3 point to C4; use Cells(3, 4) for D3.

How do I write to a sheet selected in the UserForm?

Assign the selected sheet name to a variable, such as selectedSheet, then use ThisWorkbook.Worksheets(selectedSheet).Cells(3, 4).Value = Me.FN.Value. Make sure the selected name matches an existing worksheet.

Can I use a cell address instead of row and column numbers?

Yes. For example, ThisWorkbook.Worksheets(selectedSheet).Range("D3").Value = Me.FN.Value writes the text box value to the same cell.

Why is the value going to the wrong worksheet?

An unqualified Cells reference can use the active worksheet. Prefix it with the intended workbook and worksheet, such as ThisWorkbook.Worksheets(selectedSheet).Cells(3, 4).

What file type should I use for the UserForm macro?

In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (.xlsm). Enable macros when prompted only if you trust the workbook.