Home > Articles > Home & Office Computing > Microsoft Applications

This chapter is from the book

Referencing Tables

A table is a special type of range that offers the convenience of referencing named ranges. However, tables are not created in the same manner as other ranges. For more information on how to create a named table, see Chapter 6, “Creating and Manipulating Names in VBA.”

Although you can reference a table by using Worksheets(1).Range("Table1"), you have access to more of the properties and methods that are unique to tables if you use the ListObjects object, like this:

Worksheets(1).ListObjects("Table1")

This opens the properties and methods of a table, but you can’t use that line to select the table. To do that, you have to specify the part of the table you want to work with. To select the entire table, including the header and total rows, specify the Range property:

Worksheets(1).ListObjects("Table1").Range.Select

The table part properties include the following:

  • RangeReturns the entire table.
  • DataBodyRangeReturns the data part only.
  • HeaderRowRangeReturns the header row only.
  • TotalRowRangeReturns the total row only.

What I really like about coding with tables is the ease of referencing specific columns of a table. You don’t have to know how many columns to move in from a starting position or the letter/number of the column, and you don’t have to use a FIND function. Instead, you can use the header name of the column. For example, to select the data of the Qty column of the table, but not the header or total rows, do this:

Worksheets(1).ListObjects("Table1").ListColumns("Qty")_
    .DataBodyRange.Select
  • + Share This
  • 🔖 Save To Your Account