Get Sheet Names using Power Query Excel for mac and windows

After the post “Get Sheet Names using VBA Excel for mac & windows” I started getting queries is it possible to extract the Sheet Name of the Active Workbook or any workbook using Power Query?

Well, Power Query has a solution to all our problems & it is possible by using Power Query.

Steps to follow

In order to get sheet names we must first save our Excel Workbook.

Power Query Get Data from Workbook

From the Ribbon Tab Select > Data > Get Data > From File > From Workbook

Select Workbook Get Sheet Names

Select the Excel Workbook

Power Query Navigator

Power Query Navigator will open.

Select the yellow Folder Icon as shown in the image which will select all the worksheets in that workbook.

Click on Transform Data button

Excel Workbook is loaded into the Power Query Editor and we can see all the sheet names in from that workbook in the Column [Name].

Get Sheet Names in Power Query
Power Query Editor Loaded with sheet names

Note: If need to change the file path then come to Power Query Editor click on to the Source step setting icon to change, see this blog article[coming soon] make the file path dynamic in Power Query

Get sheet name remove other columns

Select the column [Name] > Home > Remove Columns > Remove Other Columns

This action will remove all the other columns and keep only the selected column.

Shortcut Tip: Another way to deal with this just to select the column [Name] > Right Click > Remove Other Columns.

Get Sheet Names Deleted Column

We only have the column with sheet names in the Power Query editor and let rename the column name by double-clicking the column header to [Sheet Name].

Get sheet Names load data to workbook

Let’s load these sheet names into in our workbook

Home > Close & Load To..

Get Sheet Names Import Data

Select the Import Data options

  1. Table
  2. New worksheet
  3. Click OK

Power Query Academy

All sheet names for are loaded in the workbook

Sheet Names in the workbook

Lets add some new sheet name and rename the exiting default sheet name “Sheet1” to “Sheet Names”

New Sheet names Added

A very important thing to note here that once we have added the sheet we must SAVE our workbook before refreshing the query. If we accidentally forget to SAVE and refresh, then we will not get the new worksheet name.

To refresh the keep the cell in Excel Tables where all the sheet names are listed Right Click > Refresh

Get Sheet Names Unknow Sheet Names

Upon refresh, we get our new sheet names along with that we even got some other name. Let go back to our Power Query Editor and understanding what went wrong that we are getting such an unknown name in our sheet names list.

Excel Ribbon > Data > Queries & Connections > Select Query > Double Click

Query Editor will be launched and select the Source step

Get Sheet Names Source Step

After clicking the Source step we are back to the beginning of the query and looking at the column[Kind] we understand that Sheet, Excel Table & Name Ranges are also part of the workbook which gets pulled in the Power Query.

While getting the data we didn’t pull any Excel Table or Name Ranges, then how are they appearing here?

So, when we load any query into Excel Workbook it gets to load as Excel Table.

This is super amazing in-fact we can even get the Excel Table Name if we have any in our workbook.

However, to avoid this we need to make our query future proof to make sure we are getting only the sheet when new sheets are added. We can do that just by adding a FILTER step after Source step

Get Sheet Names Using Power Query Filter

Filter column[Kind] = Sheet and if you wish to exclude the “Sheet Name” then we select column[Name] filter out the from the list.

Also if we like to sort in ascending order (A-Z) then we can sort the same.

Get Sheet Name Final Result

Click Close & Load

This is a dynamic solution & future when we add any new sheet we just need to SAVE the workbook and then click refresh.

Get Sheet Name Final Result

Can we run this query on Excel for mac ?

Yes, we can run this query on Excel for Mac. Currently, the Power Query for mac is in Phase-1 for details please see this video.

The Power Query Editor yet to come for mac, but query what we have built on the PC are possible to run on mac.

Open the Excel workbook on Excel for mac

Get Names Excel for mac power query

Click on Enable Content

From the Ribbon Select > Data > Connections > Workbook Connection > Change File Path > Select the File > Get Data > Close > Save Workbook > Refresh

Run Power Query On Excel For macOS apple

Video

Subscribe to YouTube Channel for Exciting Tips & Tricks On Office Applications

Coming Soon ….


Was the information helpful in this blog?

  • If yes, hit that share button and show the excitement to the world.
  • Subscribe to our free posts.

Join 2,923 other subscribers

If no, please let us know what to improve.

Having trouble with any Office Apps. Feel free to ask and answer queries at our forums section.


5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x