How to Select a Complete Data Range with Blank Cells in Excel VBA
Question details
The user is looking for a robust VBA method to select an entire data range containing intermittent empty rows or columns without hardcoding row numbers.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Writing a VBA macro to clean raw ERP output that contains empty cells within the main data block.
- Observed behavior
- Using Selection.End(xlDown) stops at the first blank cell, leaving the rest of the data unselected and causing unreliability in the macro.
Before modifying and testing VBA code, ensure you have saved a backup copy of your workbook, especially if your macro deletes or overwrites raw data.
Use the VBA .Find Method to Determine the Last Used Row
This is the most reliable approach to find the true last row of your data, bypassing any blank cells by searching backwards through the range.
Using Selection.End(xlDown) mimics pressing Ctrl+Down, which naturally stops at the first empty cell it encounters. To select a full range containing blanks, you should completely avoid using the Select method or relying on xlDown. Instead, utilize the Find method to dynamically identify the absolute last row containing data.
In your VBA Editor, declare a variable to store the last row number. For example: Dim Lrow As Long
Use the Find method on your target range. Set SearchOrder to xlByRows and SearchDirection to xlPrevious to find the true last entry. Example: Lrow = ActiveSheet.Range("B:Z").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Now use the Lrow variable to define your full range dynamically. For example, to copy the complete range starting from row 8, use: ActiveSheet.Range("B8:Z" & Lrow).Copy

Write and Run VBA Macros Smoothly with WPS Spreadsheet
WPS Office provides robust support for VBA macros, allowing you to easily automate tasks like data cleaning, finding the last used row, and manipulating ranges containing blank cells without missing a beat.
- 1. Open your macro workbook: Launch WPS Spreadsheet and open your macro-enabled workbook (.xlsm or .xls).
- 2. Access the VBA Editor: Go to the 'Developer' tab on the ribbon and click 'Visual Basic' to open the VBA Editor.
- 3. Insert your robust code: Locate your Module, replace any Selection.End(xlDown) commands with the backward .Find method, and define your range dynamically.
- 4. Run the macro: Press F5 or click the 'Run' button on the toolbar to execute your macro and perfectly capture the full data range.

Frequently Asked Questions
Why is Selection.End(xlDown) stopping before the end of my data?
The Selection.End(xlDown) command behaves exactly like pressing the Ctrl + Down Arrow keyboard shortcut. It navigates to the edge of the current contiguous data region and stops immediately when it encounters an empty cell.
How can I find the last used column instead of the last used row?
You can use the exact same .Find method but change the search order parameter. Use SearchOrder:=xlByColumns along with SearchDirection:=xlPrevious, and append .Column at the end instead of .Row.
Can I use SpecialCells(xlCellTypeLastCell) to find the end of my data range?
While SpecialCells(xlCellTypeLastCell) is often suggested, it can be unreliable. Excel sometimes remembers previously used cells even after data has been deleted, which may cause SpecialCells to return a row number far beyond your actual current data.




