简体   繁体   中英

Select entire column in table using Excel VBA

I have a table in an excel sheet and I want to select the entire first row. Is there an easier/faster way to reference a table than the normal

 Range("A2").End(xlDown).Select 

method? Seems that by using a Table I should gain an easier access route to the data. Thanks.

With these codes you can select different parts of a table.

Entire Table:
ActiveSheet.ListObjects("Table1").Range.Select

Table Header Row:
ActiveSheet.ListObjects("Table1").HeaderRowRange.Select

Table Data:
ActiveSheet.ListObjects("Table1").DataBodyRange.Select

Third Column:
ActiveSheet.ListObjects("Table1").ListColumns(3).Range.Select

Third Column (Data Only):
ActiveSheet.ListObjects("Table1").ListColumns(3).DataBodyRange.Select

Select Row 4 of Table Data:
ActiveSheet.ListObjects("Table1").ListRows(4).Range.Select

Select 3rd Heading:
ActiveSheet.ListObjects("Table1").HeaderRowRange(3).Select

Select Data point in Row 3, Column 2:
ActiveSheet.ListObjects("Table1").DataBodyRange(3, 2).Select

Subtotals:
ActiveSheet.ListObjects("Table1").TotalsRowRange.Select

For a full guide on tables see The VBA Guide To ListObject Excel Tables .

This is the shortest way I know:

Rows(1).Select

Here you can fin some example about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM