VBA & Macro Problems

Use an Excel VBA Loop to Enter Formulas Until the First Blank Row

Jason MillerJason Miller Nov 25, 2026 870 views

Question details

Enter formulas down a worksheet with VBA and stop when a designated column reaches its first blank cell.

Use an Excel VBA Loop to Enter Formulas Until the First Blank Row
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A macro should process consecutive worksheet rows without relying on a fixed stopping row.
Observed behavior
The macro needs to stop at the first blank cell rather than at a predetermined row number.
Before you start

Choose a column that reliably identifies populated rows and a separate column for the formulas. Confirm the worksheet name and starting row before editing the macro.

Solution 1Recommended

Check a Worksheet Column for a Blank Cell in a VBA Loop

Use this approach to write formulas without selecting cells and stop when the data column is empty.

This example checks column A from row 2 and writes a formula in column B. Change the worksheet name, starting row, columns, and formula to match your workbook.

1
Open the VBA editor

In Excel, open the workbook and select Developer > Visual Basic. If the Developer tab is hidden, enable it through Excel's ribbon settings.

2
Add the macro

In the VBA editor, select Insert > Module and paste the following code: Sub FillFormulasUntilBlank() Dim ws As Worksheet Dim r As Long Set ws = ThisWorkbook.Worksheets("Sheet1") r = 2 Do While r <= ws.Rows.Count If IsEmpty(ws.Cells(r, 1).Value) Then Exit Do ws.Cells(r, 2).FormulaR1C1 = "=RC[-1]*2" r = r + 1 Loop End Sub

3
Run the macro

Replace Sheet1 with the target sheet name, then run FillFormulasUntilBlank from Developer > Macros. The example writes a formula that doubles the value in column A for each processed row.

Check a Worksheet Column for a Blank Cell in a VBA Loop
How the loop identifies a blank: IsEmpty stops at an actually empty cell in column A. A cell containing a formula that returns an empty string is not considered empty by this test.
Free Microsoft Office alternative

Work with Excel Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. Its format support helps with migration, although it does not directly fix Excel VBA issues and macro support can vary by version.

Open and edit Microsoft Excel XLSX spreadsheetsUse a familiar spreadsheet interface to work with formulasMove existing Office files into a lightweight suiteWork with spreadsheet data without a paid Office subscription
microsoft office alternative - wps office

Frequently Asked Questions

Which column determines where the loop stops?

In the example, ws.Cells(r, 1) checks column A. Change 1 to another column number if a different column identifies populated rows.

Will the loop stop if a formula returns an empty string?

No. IsEmpty treats a cell containing a formula as nonempty even if the formula displays an empty string. Use a different condition if those cells should also stop the loop.

What happens if the starting cell is blank?

The IsEmpty check exits the loop before writing a formula, so no rows are processed. Change r = 2 if the data begins on another row.

How do I keep the macro in the workbook?

Use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Run macros only when you trust their source.