How to Select from Current Cell to Top of Column with VBA in Excel
Question details
The user is looking for a VBA macro code snippet to highlight a range from the currently selected cell up to the top of its column, without having to use repetitive commands to bypass blank cells.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Writing a VBA script to dynamically select column data vertically upwards to the first row or header row, ignoring any empty cells in the range.
- Observed behavior
- Standard VBA commands like End(xlUp) may stop prematurely when encountering blank cells, necessitating a direct Range and Cells definition to select the entire span.
Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) to prevent losing your VBA code, and press ALT + F11 to access the Visual Basic Editor before beginning.
Use Range and Cells Properties to Select to Row 1
This is the most straightforward and reliable method to select all cells from your active selection up to the very first row of the same column, bypassing all blanks.
This approach dynamically defines a range starting from the currently selected cell and ending exactly at row 1 of the column where the active cell resides. It completely bypasses any empty cells that would normally disrupt an End(xlUp) command.
Press the ALT + F11 keys simultaneously on your keyboard to open the Visual Basic for Applications (VBA) Editor.
In the top menu bar, click on 'Insert' and select 'Module' to create a blank workspace for your macro.
Type or paste the following command inside your Sub procedure: Range(Selection, Cells(1, Selection.Column)).Select
Press F5 or click the 'Run' button (the green play arrow) in the toolbar. The cells from your current active cell up to row 1 will instantly be highlighted.
Select to a Specific Header Row (e.g., Row 2)
Use this method if your worksheet features headers in the first row and you only want to select the data body starting from row 2 downwards.
Use WPS Spreadsheet to Run Your VBA Macros
WPS Office provides robust, built-in support for VBA and macros. You can run, edit, and create VBA scripts exactly as you would in Microsoft Excel, but completely free of charge.
- 1. Download and Install WPS Office: Install WPS Office for free and open your macro-enabled spreadsheet (.xlsm) within the WPS Spreadsheet application.
- 2. Access the Developer Tab: Navigate to the 'Developer' tab on the top ribbon menu to access macro tools.
- 3. Open the VBA Editor: Click on 'Macros' or 'Visual Basic' to open the built-in VBA editor.
- 4. Paste and Run: Paste your column selection VBA code into the module and click 'Run' to execute the script instantly.

Frequently Asked Questions
Why does my VBA code turn red when I paste it into the macro editor?
Red text in the VBA Editor indicates a syntax error. Ensure you do not have stray parentheses or typos. For example, using `Selection.Column()` instead of the correct property `Selection.Column` will trigger a syntax error.
How can I select to the bottom of the column instead of the top?
To select from the current cell down to the last used row in the column, you can use the following snippet: `Range(Selection, Cells(Rows.Count, Selection.Column).End(xlUp)).Select`.
Does this VBA code work if I select multiple cells horizontally first?
If you have a multi-column range selected, `Selection.Column` returns the column number of the first (left-most) column in your selection. The code will select from the top-left active cell of your selection up to row 1 of that specific column.
Why does my macro select the wrong sheet's column when multiple workbooks are open?
Unqualified `Range` and `Cells` commands default to the ActiveSheet, which might change depending on user actions. To ensure accuracy, explicitly reference the worksheet, for example: `ThisWorkbook.Sheets("Data").Range(...)`.




