Enter a TextBox Value in the Next Blank Excel Cell with VBA
Question details
Use VBA to enter a TextBox value in the first empty cell in column B, starting at B2 or another specified row.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A UserForm collects a value that should be placed in the first empty cell at or below a chosen starting row.
- Observed behavior
- The TextBox value should be written to the first empty cell in column B without skipping the starting cell or earlier gaps.
Confirm the worksheet name, UserForm TextBox name, and starting row. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros if prompted and you trust the file.
Loop from the Starting Row to Find the First Empty Cell
Use this method when column B may contain gaps or the starting cell may already be empty.
In Excel, select Developer > Visual Basic, then open the UserForm containing your TextBox and submit button.
Double-click the submit button and add this code inside its Click procedure: Dim ws As Worksheet Dim r As Long Set ws = ThisWorkbook.Worksheets("DashBoard") For r = 2 To ws.Rows.Count If IsEmpty(ws.Cells(r, "B").Value) Then ws.Cells(r, "B").Value = Me.TextBox1.Value Exit Sub End If Next r MsgBox "No empty cell was found in column B."
Replace DashBoard and TextBox1 with your worksheet and control names. Change 2 to another starting row if needed, then run the UserForm and click the submit button.

Work with Excel Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for an easier move between office suites. VBA macro support can vary by edition and environment, so verify it before relying on an Excel UserForm.

Frequently Asked Questions
How do I start searching at B4 instead of B2?
In the VBA code, change For r = 2 To ws.Rows.Count to For r = 4 To ws.Rows.Count.
Will the macro fill a gap above the last used cell?
Yes. The loop checks each cell from the specified starting row and writes to the first genuinely empty cell it finds, including a gap between populated cells.
Why does the macro skip a cell that looks blank?
The cell may contain a formula returning an empty string. IsEmpty treats that cell as occupied; inspect the cell in Excel's formula bar to check.
Where should I put the TextBox code?
In the VBA editor, open the UserForm and double-click its submit button. Place the code inside that button's Click procedure and replace TextBox1 with the name of your TextBox.




