VBA & Macro Problems

Enter a TextBox Value in the Next Blank Excel Cell with VBA

Rana GarciaRana Garcia Nov 18, 2026 868 views

Question details

Use VBA to enter a TextBox value in the first empty cell in column B, starting at B2 or another specified row.

Enter a TextBox Value in the Next Blank Excel Cell with VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, select Developer > Visual Basic, then open the UserForm containing your TextBox and submit button.

2
Add the button code

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."

3
Adjust and test

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.

Loop from the Starting Row to Find the First Empty Cell
Cells with formulas: IsEmpty finds genuinely empty cells. A cell containing a formula that displays an empty string is not considered empty.
Free Microsoft Office alternative

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.

Enter and edit values in spreadsheet cells using a familiar interfaceOpen and edit Microsoft Excel formats such as .xlsxUse a free, lightweight office suiteMove between Microsoft Office and WPS Office with a familiar layout
microsoft office alternative - wps office

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.