Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
DavidBenaim
Frequent Visitor

Loading from Excel: How can I extract the sheet name of excel tables?

I am using Power Query in PowerBI with a source of an Excel file. Many of my Worksheets have 2 Excel Tables, and I want a way to map each table to the worksheet it lives in. The Default Power Query experience has different rows for tables & sheets, but I want to see an extra column where each table is mapped to a worksheet. See screenshot below. Any ideas?

 

Sheets and tables are both shown at the same granularity level, could I somehow map tables to the sheets its on?Sheets and tables are both shown at the same granularity level, could I somehow map tables to the sheets its on?

1 ACCEPTED SOLUTION

VBA code to list all sheet/table combinations with output written to worksheet "SheetTableList" (make sure to create this worksheet first).

 

Original VBA code: http://www.ozgrid.com/VBA/shapes.htm

 

Sub SheetTableList()
    Dim sobject As Object, lLoop As Long
    Dim Ws As Worksheet
    Dim wsLoop As Worksheet
    ''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''ADJUSTED CODE FROM:'''''''''''''''''''
    ''''''''''LIST PROPERTIES OF SHAPES'''''''''''''
    ''''''''''Dave Hawley www.ozgrid.com''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''
    Set Ws = Sheets("SheetTableList")
    Ws.Cells.Clear
    'Add headings for our lists. Expand as needed
    Ws.Range("A1:B1") = Array("Sheet Name", "Table")
    'Loop through all Worksheet
    For Each wsLoop In Worksheets
        For Each sobject In wsLoop.ListObjects
                'Increment Variable lLoop for row numbers
                lLoop = lLoop + 1
                With sobject
                    Ws.Cells(lLoop + 1, 1) = .Name
                    Ws.Cells(lLoop + 1, 2) = wsLoop.Name
                End With
           Next sobject
      Next wsLoop
    'AutoFit Columns.
    Ws.Columns.AutoFit
End Sub
Specializing in Power Query Formula Language (M)

View solution in original post

7 REPLIES 7
DavidBenaim
Frequent Visitor

The file is here: https://www.dropbox.com/s/avvb0owvyhs9dj7/Demand%20entry%20form.xlsx?dl=0

 

In that I also have a query "Get data>From workbook" where I only show the first "Source" step and load that to the worksheet.

 

Thanks for your help 🙂

Hi,

 

This M Query works

 

let
    Source = Folder.Files("C:\Users\Ashish\Desktop\Data"),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Content"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Custom", each Excel.Workbook([Content])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Content"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Name", "Data", "Item", "Kind", "Hidden"})
in
    #"Expanded Custom"

 

Look at the first column - that is your sheet name.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks, the Power Query shared is what I normally do, but it doesn't show the sheet name of the relevant tables, it has table names in rows, not columns.

 

VBA seems to be the solution - so thanks for sharing the code!

You get the names of your tables and the names of your sheets, but you don't get the name of the sheet with your table objects.

 

I don't think it is possible in Power Query to get the data which table is on which sheet.

 

I would suggest to try and create such a table with VBA.

Specializing in Power Query Formula Language (M)

VBA code to list all sheet/table combinations with output written to worksheet "SheetTableList" (make sure to create this worksheet first).

 

Original VBA code: http://www.ozgrid.com/VBA/shapes.htm

 

Sub SheetTableList()
    Dim sobject As Object, lLoop As Long
    Dim Ws As Worksheet
    Dim wsLoop As Worksheet
    ''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''ADJUSTED CODE FROM:'''''''''''''''''''
    ''''''''''LIST PROPERTIES OF SHAPES'''''''''''''
    ''''''''''Dave Hawley www.ozgrid.com''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''
    Set Ws = Sheets("SheetTableList")
    Ws.Cells.Clear
    'Add headings for our lists. Expand as needed
    Ws.Range("A1:B1") = Array("Sheet Name", "Table")
    'Loop through all Worksheet
    For Each wsLoop In Worksheets
        For Each sobject In wsLoop.ListObjects
                'Increment Variable lLoop for row numbers
                lLoop = lLoop + 1
                With sobject
                    Ws.Cells(lLoop + 1, 1) = .Name
                    Ws.Cells(lLoop + 1, 2) = wsLoop.Name
                End With
           Next sobject
      Next wsLoop
    'AutoFit Columns.
    Ws.Columns.AutoFit
End Sub
Specializing in Power Query Formula Language (M)
Ashish_Mathur
Super User
Super User

Hi,

 

Share the link from where i can download your Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mehaboob557
Resolver III
Resolver III

Hi @DavidBenaim,

 

Can you share me the excel ?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.