Powerquery: Naming Worksheet Tabs

numberpro11

New Member
Joined
Jul 14, 2015
Messages
9
Hello,

After doing my data transformation, when I load and save, I would like each worksheet to be named the same as the name of the query. It is really tedious having to double click and name them again, when it's the same name as the query. Is there a way to do this?

I'm using Excel 2010, and pretty much a beginner in power query, so not knowledgeable about M.

Thanks for any suggestions!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Why do you want your worksheets named the same as the table? If you need this, then you will have to use vba. The sheet and the table are separate objects
 
Upvote 0
You can use the following vba code as worksheetcode (in VBA editor (alt-F11) - select "ThisWorkbook" - view code (F7) and paste the following code:
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    If Sh.ListObjects.Count = 1 Then Sh.Name = Sh.ListObjects(1).Name
    
End Sub

If you want the Sheet name to be changed when you change the name of the query, the following code will run once you select another worksheet:

Code:
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    On Error Resume Next
    If Sh.ListObjects.Count = 1 Then Sh.Name = Sh.ListObjects(1).Name
    
End Sub

Note: while testing, I noticed that the table name from the query is adjusted only once.
Any subsequent queryname changes are not reflected in the table name, unless you close and reopen the workbook first.
 
Upvote 0

Forum statistics

Threads
1,215,615
Messages
6,125,854
Members
449,266
Latest member
davinroach

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