VBA: Reference Rows and Columns in Excel
Selecting rows and columns is a fairly simple task in Excel.
Selecting A Column
To select a column click the letter at the top of the desired column. See below example:
Selecting a Row in Excel
To select a row click the number to the left of the desire row. See below for example:
Referencing Columns in VBA
There are two methods for selecting columns in visual basic.
- Using the Column Name
- Using the Column Index Number
Reference Column Using Name
'reference column F
Reference Column Using Index Number
'reference column F (6th column)
Referencing a Row in Visual Basic
'reference row 1
Referencing the Row or Column where a Cell Resides
'references the column in which "A1" resides, therefore column A
'references the row in which "A5" resides, therefore row 5
Now that you know how to reference a column or column, you can perform a large number of tasks in VBA. Here are a few examples.
Delete Column A
Delete Row 1
Clear contents Column A
Clear contents Row 1
Insert a Column to the Left of Column A
Insert a Row before Row 1
Ready to Proceed?
In the next module we will look at setting column width and using autofit in Excel and VBA.