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
Search our website
We also send out useful tips in a monthly email newsletter ...
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!
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.
|
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:
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.
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.
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.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2023. All Rights Reserved.