Excel VBA: Skip Blank Cells and Find the Next Nonblank Cell
Question details
Find nonblank cells efficiently with a VBA loop that processes each row from left to right.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A macro scans approximately 600 columns starting at column D across approximately 150 rows, beginning with row 2.
- Observed behavior
- Many cells are blank, and the loop needs to handle empty rows and trailing blanks without losing the required row-by-row order.
Confirm the worksheet name and the last row and column to scan. Open the VBA editor with Alt+F11, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if it needs to retain the macro.
Use Find to process populated cells in row order
Search each bounded row from column D onward, stopping when Find returns no result or wraps back to an earlier column.
This example searches 600 columns starting at D and rows 2 through 150. Adjust the worksheet name and boundaries to match your data.
The search uses xlFormulas, so a cell containing a formula is included even if the formula displays an empty string. Truly empty cells are skipped.
In Excel, press Alt+F11 and select Insert > Module.
Paste the following macro into the module, then replace Sheet1 with your worksheet name: Sub ProcessNonblankCells() Dim ws As Worksheet Dim scanRange As Range, found As Range, afterCell As Range Dim r As Long, k As Long, previousCol As Long Const firstRow As Long = 2 Const lastRow As Long = 150 Const firstCol As Long = 4 Const columnCount As Long = 600 Set ws = ThisWorkbook.Worksheets("Sheet1") For r = firstRow To lastRow Set scanRange = ws.Range(ws.Cells(r, firstCol), _ ws.Cells(r, firstCol + columnCount - 1)) Set afterCell = scanRange.Cells(1, scanRange.Columns.Count) previousCol = firstCol - 1 Do Set found = scanRange.Find(What:="*", After:=afterCell, _ LookIn:=xlFormulas, LookAt:=xlPart, _ SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) If found Is Nothing Then Exit Do If found.Column <= previousCol Then Exit Do k = found.Column Debug.Print found.Address, k, found.Value ' Add your processing code here. previousCol = k Set afterCell = found Loop Next r End Sub
In the VBA editor, select the macro and press F5. Open View > Immediate Window to check the addresses and column numbers, then replace or extend the Debug.Print line with your processing code.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Excel spreadsheets. Its format compatibility helps you move existing files into your everyday workflow; check macro support before relying on Excel VBA code.

Frequently Asked Questions
Does the macro finish one row before moving to the next?
Yes. The outer For loop selects one row at a time, and Find searches from column D to the specified last column before the loop advances to the next row.
What happens if a row is empty or ends with blank cells?
If Find returns Nothing, the inner loop exits. If it wraps to a previously processed column after reaching the last populated cell, the column check exits the loop.
How do I get the column number from a cell address stored as text?
Use k = ws.Range(strAddress).Column, where ws is the worksheet containing the address. A text string does not have a Column property by itself.
Will the search include formulas that display a blank?
Yes. With LookIn:=xlFormulas, Find searches the stored formula, so a formula returning an empty string can be included.
How can I change the scan boundaries?
In the VBA module, change firstRow, lastRow, firstCol, or columnCount. Column D is column 4, and a columnCount of 600 scans 600 columns starting there.




