VBA: Select Range to End of Data (Step-by-Step)
In this article
To select from the active cell to the end of the contiguous data in Excel VBA, use Range(Selection, Selection.End(xlDown)) for a column, Range(Selection, Selection.End(xlToRight)) for a row, or the one-liner Range("A1").CurrentRegion.Select to grab the whole block. These mimic the Ctrl+Shift+Arrow shortcuts and stop at the first blank cell, so the data must be contiguous.
What You'll Need
- Excel with macros enabled (a .xlsm workbook or the Personal Macro Workbook).
- The Developer tab visible: File > Options > Customize Ribbon > check Developer. Labels can differ slightly by version and region.
- A worksheet with a contiguous block of data and no blank rows or columns inside it.
Step-by-Step
- Open the workbook and press Alt+F11 to open the VBA Editor.
- In the Project Explorer, right-click your workbook and choose Insert > Module. A blank code window opens.
- Type
Sub SelectToEnd()and press Enter; the editor addsEnd Sub. - Inside the sub, set the starting cell. For example
Range("A1").SelectorRange("B5").Select. - Add the selection line. For a column:
Range(Selection, Selection.End(xlDown)).Select. For a row:Range(Selection, Selection.End(xlToRight)).Select. - Press F5 to run. The range from your start cell down (or right) to the last non-blank cell is selected.
- To select the entire block including headers, replace the two lines with
Range("A1").CurrentRegion.Select. This expands in all directions until blank rows and columns. - To work with the range without selecting it, assign it to a variable:
Dim rng As RangethenSet rng = Range(Range("A1"), Range("A1").End(xlDown)). Userngin later code. - To make it dynamic from the active cell, use
Range(ActiveCell, ActiveCell.End(xlDown)).Select. - Save the workbook as .xlsm (File > Save As > Excel Macro-Enabled Workbook) so the code is kept.
Common Mistakes
- Blank cells inside the data.
End(xlDown)stops at the first blank, so the selection ends early. Fill gaps or useCurrentRegiononly if the block is truly contiguous. - Starting on a blank cell.
End(xlDown)from a blank cell jumps to the next non-blank cell, which can select the wrong area. Always start on a cell with data. - Using Select when not needed. Selecting slows code and can fail if the sheet is not active. Work with Range variables instead.
- Assuming the last row is the last used row.
End(xlDown)finds the last cell before a blank, not necessarily the sheet's true last row. For that, useCells(Rows.Count, 1).End(xlUp). - Forgetting the sheet reference. Unqualified
Rangecalls act on the active sheet, which may not be the one you expect.
Tips
- Use
xlUpfrom the bottom of the sheet to find the true last row:Range("A" & Rows.Count).End(xlUp).Row. - Combine start and end for a full column:
Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Select. - For a whole table,
CurrentRegionis usually the cleanest one-liner. - Turn off ScreenUpdating while the macro runs to speed it up:
Application.ScreenUpdating = False, then set it back toTrueat the end. - Use
Offsetto skip headers:Range("A1").Offset(1, 0)starts one row down.
Troubleshooting
If the macro selects only one cell, the start cell is probably blank or the data has a gap. Check for empty cells and fill them or switch to CurrentRegion. If you get a "Select method of Range class failed" error, the worksheet is not active; add Worksheets("Sheet1").Activate before selecting, or better, avoid Select entirely. If the selection runs to the bottom of the sheet, End(xlDown) hit a blank and jumped to the last row; use End(xlUp) from the bottom instead. If nothing happens, confirm macros are enabled and the code is in a standard module, not a sheet module. If the wrong sheet is affected, qualify every Range with a worksheet object.
Frequently Asked Questions
Why does End(xlDown) stop early?
It stops at the first blank cell in the column. Data must be contiguous; fill gaps or use CurrentRegion.
How do I select to the last row of the sheet?
Use Range("A1", Cells(Rows.Count, 1)).Select or Range("A1").End(xlDown) if data is contiguous.
Can I select multiple columns to the end of data?
Yes: Range("A1:C1").Select then Range(Selection, Selection.End(xlDown)).Select extends all three columns together.
What is the difference between End(xlDown) and CurrentRegion?
End(xlDown) goes in one direction until a blank. CurrentRegion expands in all directions around the start cell until blank rows and columns, like Ctrl+A.
Why do I get a Select method error?
The sheet is not active or the range is on a different sheet. Activate the sheet first or assign the range to a variable instead of selecting.
Can I use this in a loop?
Yes, but avoid Select inside loops; assign each range to a variable and process it directly for speed and reliability.