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 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!
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.
|
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:
Sub SelectPoohBear()
'select cell B5 (it's not case sensitive)
Range("B5").Select
End Sub
Or you can do it using the row and column number:
Sub SelectPoohBear2()
'select row 5, column 2
Cells(5, 2).Select
End Sub
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:
Sub SelectCharacters()
'again, this isn't case sensitive
Range("B3:B11").Select
End Sub
Alternatively, you could use the range name, where (as here) one exists:
Sub SelectCharacters()
'type the range name in quotes
Range("Characters").Select
End Sub
Now it's time to look at some less common 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.