Reference Tables in VBA

Skybluekid

Well-known Member
Joined
Apr 17, 2012
Messages
1,231
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I wonder if someone could point me in the right direction. I have an excel table, named Customers. In the table, there are two columns, Customer and PO, I would like reference that table within a VBA Index Function.

I have looked everywhere for an answer but I am not geting very far.

Could do with pointing in the right direction.

Thanks in Advance.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
What in the table do you want to reference?

There are various ways to refer to tables in VBA, here are some examples.
Code:
Dim rngTbl As Range
Dim tbl As ListObject
Dim rngCol As Range
Dim tblCol As ListColumn

    Set rngTbl = Range("Customers") 'range reference to entire table
    Debug.Print rngTbl.Address
    Debug.Print
        
    Set tbl = ActiveSheet.ListObjects("Customers") ' list object reference to table
    Debug.Print tbl.Range.Address
    Debug.Print
    
    Set rngCol = Range("Customers[Customer]") ' range reference to 'Customer' column
    Debug.Print rngCol.Address
    Debug.Print
    
    Set tblCol = ActiveSheet.ListObjects("Customers").ListColumns("Customer") ' listcolumn reference to table
    Debug.Print tblCol.Range.Address
    Debug.Print
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top