564 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Selecting Cells using Excel VBA Macros - Absolute
Part three of a four-part series of blogs
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!
Sometimes you'll want to select entire rows or columns, or even every cell in a worksheet. Here's how:
You can do this using the Columns collection. For example:
'select one column
'select several columns
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.
You can select rows in the same way, but using the Rows collection:
'select one row
'select several rows
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.
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
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.
|Parts of this blog|
25 Aytoun Street