Selecting Rows and Columns

Excel uses the EntireRow and EntireColumn properties to select the entire row or column.

To render this into VBA:

Enter this in the Immediate window:

Select an entire row where the active


cell is located.

Select an entire column where the


active cell is located.

When you select a range of cells you may want to find out how many rows or columns are included in the selection. Let's have Excel count rows and columns in Range("A1:D15").

1. Enter the following VBA statement in the Immediate window: Range("A1:D15").Select

If the Microsoft Excel window is visible, when you press Enter, VBA will highlight the range A1:D15.

2. To find out how many rows are in the selected range, enter the following statement:


As soon as you press Enter, VBA displays the answer on the next line. Your selection includes 15 rows.

3. To find out the number of columns in the selected range, enter the following statement:


Now VBA tells you that the selected Range("A1:D15") occupies the width of four columns.

4. Position the cursor anywhere within the word Rows or Columns, and press F1 to find out more information about these useful properties.

0 0

Post a comment