引用表中定义的一列

如何引用由表定义的范围中的单个列?

Dim LandscapingDataRange As Range Set LandscapingDataRange = ThisWorkbook.Worksheets(Sheet6.Name).ListObjects("TableReportLandscaping").DataBodyRange LandscapingSiteMatch = Application.WorksheetFunction.Match(ContactListRange(MailCounter, 3), LandscapingDataRange(3), 0 

我只想参考LandscapingDataRange中的第三列,但上面只涉及到一个单元格。

用我的编程,我很努力不要混淆自己:)所以我通常初始化一组“标准”的对象,以提供我所需要的访问。 根据表格中的数据和列可能更改的频率,我有时select按名称而不是数字访问列。

 Option Explicit Sub test() Dim ws As Worksheet Dim tblLandscaping As ListObject Dim tblLandscapingDBR As Range Dim tblLandscapingDataCol As Range Dim colName As String Set ws = ActiveSheet Set tblLandscaping = ws.ListObjects("TableReportLandscaping") Set tblLandscapingDBR = tblLandscaping.DataBodyRange Debug.Print "address range of DataBodyRange = " & tblLandscapingDBR.Address & _ " num rows = " & tblLandscapingDBR.Rows.Count & _ " cols = " & tblLandscapingDBR.Columns.Count Set tblLandscapingDataCol = tblLandscaping.ListColumns(3).DataBodyRange Debug.Print "address range of column 3 = " & tblLandscapingDataCol.Address & _ " num rows = " & tblLandscapingDataCol.Rows.Count colName = tblLandscaping.Name & "[Contracts]" Set tblLandscapingDataCol = ws.Range(colName) Debug.Print "address range of column 'Contracts' = " & tblLandscapingDataCol.Address & _ " num rows = " & tblLandscapingDataCol.Rows.Count End Sub