Use an Excel VBA Loop to Enter Formulas Until the First Blank Row
Question details
Enter formulas down a worksheet with VBA and stop when a designated column reaches its first blank cell.

- 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.
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.
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.
In Excel, open the workbook and select Developer > Visual Basic. If the Developer tab is hidden, enable it through Excel's ribbon settings.
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
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.

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.

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.




