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 two 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!
You want to go to a cell or range of cells using a macro written in Visual Basic for Applications within Excel. Here's how!
For all of the examples below, assume that you want to select the cell containing Pooh Bear (who wouldn't?).
There are two ways to select a single cell. You can either do it by cell reference:
'select cell B5 (it's not case sensitive)
Or you can do it using the row and column number:
'select row 5, column 2
Either way works fine - the choice is up to you.
The method using Cells(row,column) can be particularly useful when looping over cells, since the row and column can be variables.
If you've got a block of cells, you can select them by cell reference or by range name:
In this case we want to select the range from B3 to B11, which also has the range name Characters.
To select a range of cells by reference, use a colon to separate the start and end cell:
'again, this isn't case sensitive
Alternatively, you could use the range name, where (as here) one exists:
'type the range name in quotes
Now it's time to look at some less common selection commands ...
|Parts of this blog|
25 Aytoun Street