ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

VBA: Reference Rows and Columns in Excel

Updated on August 22, 2012

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

Columns("F")

Reference Column Using Index Number

'reference column F (6th column)

Columns(6)

Referencing a Row in Visual Basic

'reference row 1

Row(1)

Referencing the Row or Column where a Cell Resides

'references the column in which "A1" resides, therefore column A

Range("A1").entirecolumn

'references the row in which "A5" resides, therefore row 5

Range("A5").entirerow

Common Tasks

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

Columns("A").delete

Delete Row 1

Rows(1).delete

Clear contents Column A

Columns("A").ClearContents

Clear contents Row 1

Row(1).ClearContents

Insert a Column to the Left of Column A

Columns("A").insert

Insert a Row before Row 1

Row(1).insert

Ready to Proceed?

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.