Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select entire column in table using Excel VBA

Tags:

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.

like image 846
Ben A Avatar asked Apr 21 '17 11:04

Ben A


People also ask

How do you select an entire column in a table?

You can also click anywhere in the table column, and then press CTRL+SPACEBAR, or you can click the first cell in the table column, and then press CTRL+SHIFT+DOWN ARROW. Note: Pressing CTRL+SPACEBAR once selects the table column data; pressing CTRL+SPACEBAR twice selects the entire table column.

How do I select all cells in a column in Excel VBA?

To manually select all the data in a column, select the first cell, and press CTRL+SHIFT+DOWN ARROW.


1 Answers

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.

like image 121
Pᴇʜ Avatar answered Sep 22 '22 07:09

Pᴇʜ