Introduction to Programming Macros in Excel
First Steps
Getting and Inputting Data
Adding Logic to Macros
UDF- User Defined Functions
Speeding Up Macros

Select Ranges of Cells in Excel using Macros and VBA

Add to Favorites
Author: don

This Excel VBA tutorial focuses specifically on selecting ranges of cells in Excel.  This means that you will learn how to select multiple contiguous cells in the same row, column, or worksheet.  There are many ways to do this but, below, I will show you the simplest way to select ranges with VBA.

Sub Select_Cells_in_Excel()

'Select a range of cells in the current worksheet

Range("A1", "B5").Select

End Sub

Put the above macro in your workbook and you will more clearly be able to see the comments and the two lines of actual code.

As you can see, it is really easy to select a range and, logically enough, you use the Range method to do so.

To select a range just start with Range and then input the desired range of cells to select or work on.  If you want to select the range A1:A5, input Range(A1:A5).Select and thats it.  Remember that this will select the range on the currently active or visible worksheet in Excel.

All you have to do to select a different range is to change A1 and A5 to whatever you want.  Note, to select a range, the first cell reference that you input should be for the cell in the upper left part of the range; the second cell reference that you input should be for the bottom right part of the range that you want to select.

If you wanted to select all the cells in columns A, B, & C and all the rows from 1 to 10, you would use this piece of code: Range(A1:C10).Select

You will also notice that there is a second way to reference a range using Range in Excel and there are actually a few other, but much more complicated, ways to do so.  The second method above is used much like the first.  The upper left cell reference for the range is the first reference and the lower right cell reference for the range is the second number.  But, unless you need to do more complex things in Excel, I would stick to using the first method, it is much easier to understand and read later when you go over your VBA code.

Question? Ask it in our Excel Forum