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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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