|
Home > Macros > Basics > Tables Excel Table Macros
|
| ▶ |
Tip: If you need a macro to copy and paste selected table rows, go to the Copy Excel Table Rows page. |
The following macros will list all the named Excel Tables in the active workbook.
A new worksheet is inserted, and the table name, sheet name, table address, and source type are listed.


| ▶ |
Tech Tip: You can find more info on SourceType on the Microsoft website. |
Copy the following VBA macro code to a regular code module, then run the macro when needed..
Sub ListTables()
Dim ws As Worksheet
Dim Lst As ListObject
Dim wsL As Worksheet
Dim lCount As Long
''Source Type: 0 external; 1 Range;
'' 2 XML; 3 Query; 4 PowerPivot Model
lCount = 1
Set wsL = Worksheets.Add
With wsL.Range("A1:E1")
.Value = Array("ID", "Table", "Location", _
"Sheet", "Source Type")
lCount = lCount + 1
End With
For Each ws In ActiveWorkbook.Worksheets
If ws.ListObjects.Count > 0 Then
For Each Lst In ws.ListObjects
wsL.Cells(lCount, 1).Value = lCount
wsL.Cells(lCount, 2).Value = Lst.Name
wsL.Cells(lCount, 3).Value = Lst.Range.Address
wsL.Cells(lCount, 4).Value = ws.Name
wsL.Cells(lCount, 5).Value = Lst.SourceType
lCount = lCount + 1
Next Lst
End If
Next ws
End Sub
Copy the following VBA macro code to a regular code module, then run the macro when needed.
Sub ListTablesSource()
Dim ws As Worksheet
Dim Lst As ListObject
Dim wsL As Worksheet
Dim lCount As Long
Dim strST As String
lCount = 1
Set wsL = Worksheets.Add
With wsL.Range("A1:E1")
.Value = Array("ID", "Table", "Location", _
"Sheet", "Source Type")
lCount = lCount + 1
End With
For Each ws In ActiveWorkbook.Worksheets
If ws.ListObjects.Count > 0 Then
For Each Lst In ws.ListObjects
Select Case Lst.SourceType
Case 0: strST = "External"
Case 1: strST = "Range"
Case 2: strST = "XML"
Case 3: strST = "Query"
Case 4: strST = "PowerPivot Model"
Case Else: strST = "Unknown"
End Select
wsL.Cells(lCount, 1).Value = lCount
wsL.Cells(lCount, 2).Value = Lst.Name
wsL.Cells(lCount, 3).Value = Lst.Range.Address
wsL.Cells(lCount, 4).Value = ws.Name
wsL.Cells(lCount, 5).Value = strST
lCount = lCount + 1
Next Lst
End If
Next ws
End Sub
If Excel tables are not expanding automatically on your computer, there are two Excel Table AutoFormat settings that you can turn on or off:
| ⚠️ |
Warning: Changing these settings will affect all workbooks that you open in Excel, on your computer. They are application-level settings. |
First, this short video shows how to change these table settings manually, and there are detailed steps on the Excel Tables Fix Expand page.
Or, use the two macros in the next section, turn the two Excel Table AutoFormat settings on or off.
This macro will turn the two Excel Table AutoFormat settings ON.
Copy the following VBA macro code to a regular code module, then run the macro when needed.
Sub ListAutoSetOn() With Application.AutoCorrect .AutoExpandListRange = True .AutoFillFormulasInLists = True End With End Sub
This macro will turn the two Excel Table AutoFormat settings OFF.
Copy the following VBA macro code to a regular code module, then run the macro when needed.
Sub ListAutoSetOff() With Application.AutoCorrect .AutoExpandListRange = False .AutoFillFormulasInLists = False End With End Sub
Thanks to Alex Blakenburg, who shared the following code for getting the sheet name for a specific Excel table. Alex needed code to make changes to a named Excel table, and to its worksheet, and there were a few things to consider:
To address those issues, Alex used these settings in these macros:
In the sample file, the TblInfo sheet has a drop down list, where you can choose a table name. That triggers a Change event procedure, which clears a couple of cells, and runs the following macro - ShowTableInfo.

Here is the Change event procedure on the TblInfo sheet, which runs automatically after you select a table name:
Private Sub Worksheet_Change _
(ByVal Target As Range)
If Target.Address = _
Range("SelTbl").Address Then
Range("TblSh").ClearContents
Range("TblAd").ClearContents
If Target.Value <> "" Then
ShowTableInfo
End If
End If
End Sub
And here is the ShowTableInfo macro, which the event procedure (above) runs.
Sub ShowTableInfo()
'by Alex Blakenburg
'select table name in SelTable cell
' table's sheet and address
' added to cells below
Dim wb As Workbook
Dim shTI As Worksheet
Dim shData As Worksheet
Dim SelTable As Range
Dim TblSheet As Range
Dim TblAddr As Range
Dim rngTbl As Range
Dim tblData As ListObject
Dim tblName As String
Dim tblFullName As String
Set wb = ActiveWorkbook
Set shTI = wb.Sheets("TblInfo")
Set SelTable = shTI.Range("SelTbl")
Set TblSheet = shTI.Range("TblSh")
Set TblAddr = shTI.Range("TblAd")
tblName = SelTable.Value
If tblName = "" Then Exit Sub
tblFullName = "'" & wb.Name _
& "'!" & tblName
Set rngTbl = Range(tblFullName)
Set shData = _
wb.Sheets(rngTbl.Parent.Name)
Set tblData = _
shData.ListObjects(tblName)
TblSheet.Value = shData.Name
TblAddr.Value = _
tblData.Range.Address
End Sub
The sample file also has two macros that can be tested with the buttons on the Testing worksheet. These two macros show how the target table and its sheet can be changed, even when their workbook is not active.
You can get both macros when you download the sample workbook.

Last updated: February 14, 2026 3:54 PM