BLOGS BY TOPIC▼
BLOGS BY AUTHOR▼
BLOGS BY YEAR▼
This blog gives the various possible ways to select cells, ranges, columns and rows using Visual Basic for Applications in Excel. Useful for the VBA newbie, but even gurus might find one or two commands they'd missed!
- Selecting Cells in Excel Visual Basic Macros (Absolute)
- Absolute Selection - the Common Excel VBA Commands
- Selecting Rows, Columns and Entire Worksheets (this blog)
- Less Common Absolute Selection Commands
This blog is part of our Excel macros online tutorial series. For real-world training, book onto our introductory or advanced VBA or Excel courses.
Posted by Andy Brown on 11 August 2011
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Selecting Rows, Columns and Entire Worksheets
Sometimes you'll want to select entire rows or columns, or even every cell in a worksheet. Here's how:
Selecting Columns
You can do this using the Columns collection. For example:
Sub SelectColumns()
'select one column
Columns("B").Select
'select several columns
Columns("B:D").Select
End Sub
The above macro would select column B, then columns B through to D:

The result of running the above macro.
Note that you can select a single column by number too - for example, Columns(2).Select - but this method doesn't work for a range of columns.
Selecting Rows
You can select rows in the same way, but using the Rows collection:
Sub SelectRows()
'select one row
Rows("2").Select
'select several rows
Rows("2:4").Select
End Sub
The above routine would leave rows 2 through to 4 selected:

The results of running the macro above.
Note that as for columns you can dispense with the quotation marks if you're selecting a single row. So Rows(2).Select would also select the second row.
Selecting Every Cell in a Worksheet
In Excel you can select every single cell by clicking on the square at the top left corner of a worksheet:

Click on the square shown to select every cell in a worksheet.
The VBA equivalent command to select every single cell in a sheet is:
'select every cell in a worksheet
Cells.Select
Having seen how to select cells, rows and columns, it's time to complete the picture by showing some of the less commonly used selection commands.
- Selecting Cells in Excel Visual Basic Macros (Absolute)
- Absolute Selection - the Common Excel VBA Commands
- Selecting Rows, Columns and Entire Worksheets (this blog)
- Less Common Absolute Selection Commands