VBA & Macro Problems

Find the Last Used Row Across Multiple Excel Columns with VBA

Natalie TaylorNatalie Taylor Nov 25, 2026 870 views

Question details

Find the last used row across Excel columns B through E, including when one or more columns are empty.

Find the Last Used Row Across Multiple Excel Columns with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA macro needs to determine the lowest row containing data anywhere in columns B:E.
Observed behavior
A search limited to one column can miss data in other columns if that column is empty or ends earlier.
Before you start

Open the workbook in Excel and identify the worksheet to search. If you need to keep the macro in the workbook, save it as an Excel Macro-Enabled Workbook (.xlsm).

Solution 1Recommended

Search columns B:E with the VBA Find method

Use Find to search all four columns by row and safely handle an empty range.

The search uses xlFormulas, so cells containing formulas count as used even if a formula displays an empty string. It returns the row number of the lowest matching cell in B:E.

1
Open the VBA editor

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

2
Insert a module

In the VBA editor, select the workbook in the Project pane, then choose Insert > Module.

3
Add and run the macro

Paste the following code into the module. Run it from Excel using Developer > Macros, or run it from the VBA editor: Sub FindLastRowInColumns() Dim ws As Worksheet Dim lastCell As Range Dim lastRow As Long Set ws = ActiveSheet Set lastCell = ws.Range("B:E").Find(What:="*", After:=ws.Range("B1"), _ LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False) If Not lastCell Is Nothing Then lastRow = lastCell.Row MsgBox "Last used row in B:E: " & lastRow Else MsgBox "Columns B:E contain no data." End If End Sub

Search columns B:E with the VBA Find method
Choose the intended worksheet: The example searches the active sheet. To search a specific sheet in the workbook containing the macro, replace ActiveSheet with ThisWorkbook.Worksheets("YourSheetName").
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative for opening and editing spreadsheets with a familiar interface. It supports common Excel formats to help you move between office suites; VBA macro support and behavior can vary by WPS version and platform.

Inspect and edit data across multiple spreadsheet columns.Open and work with Microsoft Excel formats such as .xlsx and .xlsm.Use a familiar spreadsheet interface for an easier transition from Excel.Work with office documents in a lightweight, free suite.
QA img-9

Frequently Asked Questions

What happens if all cells in columns B:E are empty?

Range("B:E").Find returns Nothing. Check If Not lastCell Is Nothing before reading lastCell.Row to avoid an error.

Will the macro find a row if column B is empty?

Yes. The Find call searches the entire B:E range, so a matching cell in column C, D, or E can determine the last row.

Do formulas that display an empty string count as used?

Yes. The example uses LookIn:=xlFormulas, which searches formula contents even when their displayed result is empty.

How can I search a named worksheet instead of the active one?

Replace Set ws = ActiveSheet with Set ws = ThisWorkbook.Worksheets("YourSheetName"), using the actual worksheet tab name.

Why not use UsedRange to find the last row in B:E?

UsedRange covers the worksheet's used area, not just columns B:E, and formatting or previous edits can extend it. Searching Range("B:E") restricts the result to those columns.