VBA & Macro Problems

How to Select from Current Cell to Top of Column with VBA in Excel

Huma Ashraf ChHuma Ashraf Ch Nov 10, 2026 869 views

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.

How to Select from Current Cell to the Top of a Column Using Excel VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press the ALT + F11 keys simultaneously on your keyboard to open the Visual Basic for Applications (VBA) Editor.

2
Insert a New Module

In the top menu bar, click on 'Insert' and select 'Module' to create a blank workspace for your macro.

3
Input the Selection Code

Type or paste the following command inside your Sub procedure: Range(Selection, Cells(1, Selection.Column)).Select

4
Run the Macro

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.

Qualifying Worksheets: To avoid unexpected errors when working with multiple open sheets, qualify your range with the specific worksheet object. For example: Worksheets("Sheet1").Range(Selection, Worksheets("Sheet1").Cells(1, Selection.Column)).Select.
Free Excel Alternative with VBA Support

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. 1. Download and Install WPS Office: Install WPS Office for free and open your macro-enabled spreadsheet (.xlsm) within the WPS Spreadsheet application.
  2. 2. Access the Developer Tab: Navigate to the 'Developer' tab on the top ribbon menu to access macro tools.
  3. 3. Open the VBA Editor: Click on 'Macros' or 'Visual Basic' to open the built-in VBA editor.
  4. 4. Paste and Run: Paste your column selection VBA code into the module and click 'Run' to execute the script instantly.
Fully compatible with Microsoft Excel (.xlsm) macro files and syntaxIncludes a built-in Visual Basic Editor for writing and debugging custom scriptsLightweight application that runs smoothly on older or low-spec devicesSeamless migration with familiar formulas, UI, and keyboard shortcuts
microsoft office alternative - wps office

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(...)`.