Getting the Current Table Name

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
2,795
Office Version
  1. 365
Platform
  1. Windows
I'm starting to see the value of using Excel Tables rather than dynamic named ranges. I know I can get ranges and headers from the table by direct reference. How do I get the name of the current Table?

I have 3 sheets, each with an Excel Table laid out with the exact same headers. Open Items, Approved Items, Completed Items. Lots of Sheet triggers are built in and I need to know what table name is from the target cell.

So I can use it like this:
VBA Code:
TblName = CurrentTable                                       <<<< Unknown
Set R = Range(TblName & "[[Quote]:[Doc]]"

VBA Code:
Sub Macro9()
  Dim R As Range

  Range("ApprovedItems_tbl[[Quote]:[Doc]]").Select

  Set R = Range("ApprovedItems_tbl[[Quote]:[Doc]]")

End Sub
[/Quote]
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How about
VBA Code:
  Dim Tbl As ListObject
  Set Tbl = ActiveCell.ListObject
  Debug.Print Tbl.Name
 
Upvote 0
Cool! Thank you

Is there a way to use Tbl as an object to get the columns without using the Tbl.name? Like Tbl.range("[Site Name"]") OR Tbl.range("Site Name")? What is Tbl.ListColumns() do?
 
Upvote 0
How about
VBA Code:
  Tbl.ListColumns("site Name").DataBodyRange.Select
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
I am trying to search the MS reference before asking. I need some more input. I'm trying to get a range between to columns in the table. I know I can get that using the first method I posted, but how do I do it using the table as a listobject? I can get a single column.

VBA Code:
Sub Test()
  Dim Tbl As ListObject
  Dim LC As ListColumns
  
  Set Tbl = ActiveCell.ListObject
  Set LC = Tbl.ListColumns
  
  LC("Site Name").DataBodyRange.Select
  Range(LC("Site Name").DataBodyRange, LC("Vendor").DataBodyRange).Select     '<<<<<<< Error
  Debug.Print LC("Site Name").Index
  
End Sub
 
Upvote 0
Check that the Vendor column is the correct name.
What error do you get?
 
Upvote 0
MWR Project Tracker5.xlsm
BCDEFGHIJKLMNOPQRSTUVWX
2StateSite NameDisciplineDescriptionVendorOwnerStatusOrig WO IDCM WO IDQuoteDocQuoted PriceInception DateRequest Approval DateApproval DateScheduled DateCompleted DateCancelled DateLast Status ChangeInception To Request ApprovalApproval PeriodApproval to CompletionTotal Days
3UTWilmingtonHVACFour Compressors for RTU#4 are down Replace only units #1 and #3. #5 is under warranty. Decision to replace units around August - September From CS: September 2019 we replaced compressors #2 & #7 Now we are reporting that compressors #1, #3, #4 need to be replaced, and #5 is noisy * Working with Comfort Sytems to determine which units are under warranty * Compressor #5 should be under Warranty * 2019 Compressors #2 and #7 were replaced in September * 7 Compressors on unit #3 and #4 need to be replaced. #5 is noisy * Need CS to audit all the Compressors and update the details before accepting quote *Quote submitted to Liz 6/8 *Investigating compressor sub-assetsComfort Systems USA IntermountainTomPending Customer ApprovalQuote 060 $ 26,733 6/8/20206/30/202023  23
Open Items
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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