MS Excel

Import all sheets from all files in a folder into Excel

This is the second post of a series that covers everything about importing all files in a folder. Click here to see the series of post.

In this scenario I’ll show you to import all sheets from all excel files in a folder.  If you want to follow along, download the files from this link.

Important: I’ll show how to import all sheets from all Excel files in a folder, however, it is the same process if the files contain just one sheet.

Step 1: Import the files from the desired folder

Go to Data -> New Query -> From File -> From Folder

 

Click on ‘Browse’ and browse for the folder that contain the files, then click OK.

Once you click OK, press Edit on the next window.

Then you’ll see a window with several details of each file in the folder such as Extension, Date accessed, Date modified, etc.

We’re only interested in the Content column, therefore, right-click on the header of the Content column and select Remove Other Columns.

The go to Add Column -> Add Custom Column

 

Step 2: Extract the contents from each file

In the next dialog box, type a name for the new column (e.g. FileContent) and the custom formula: =Excel.Workbook([Content], true) and click OK.

 

Note: The second argument of the function Excel.Workbook is to promote the headers from each sheet. If you don’t set this argument to true, you’ll have to promote the headers afterwards and then filter out the headers from the data.

Then click on the column and click OK in the Expand dialog box.

 

Then go to the filter button of the FileContent.Kind column, select Sheet and click OK.

Right-click the header of the FileContent.Data column and select Remove Other Columns.

Then click in the Expand button in the column FileContent.Data

In the next dialog box, make sure to uncheck the option “Use original column name as prefix” and click OK.

The data from ALL SHEETS from ALL FILES should be visible now. Isn’t this amazing?

Now make any further changes needed. For example, change the format of the Date column to date (Right-click the header of the Date Column, go to Change Type -> Date)

Step 3: Load the data into Excel

Go to File -> Close & Load To…

 

Select Table and the destination of the results (New worksheet or Existing worksheet), then click on Load.

That’s All!!!

Click here if you want to see the other posts in the series.

Want to continue learning about automating your data preparation processes?? Subscribe to the blog.

Please share this post so more people can benefi!.

Newsletter

Stay up to date with our latest news, receive exclusive deals, and more.

© Master Data Analysis All Rights Reserved 2024

Orlando Mezquita

Love helping out people to get better using data analysis tools! My day job is statistician for a Pharmaceutical Company.

View Comments

  • uhhh... stupid question: will the Power Query steps be captured by a Macro Recording? don't seem to be.

    • Hi Joe,
      Actually, that's a very good question and one of the cool features of Power Query.

      When you perform the data cleaning steps in Power Query, these steps are "recorded" in a language called M. This allows you to repeat all your data transformation steps just by clicking on Refresh. So it's like macro recording, but much more flexible.

Share
Published by
Orlando Mezquita

Recent Posts

18 courses to learn R in 2018

Do you want to learn or get better at R programming?  If yes, you will…

7 years ago

Calculating the median in Excel PivotTables

Go to Master Data Analysis Yes, you read the title of this post correctly, you…

7 years ago

Using R to predict if a customer will buy

In this post, I’ll show how to create a simple model to predict if a…

8 years ago

Data Science for Beginners

Are you wondering what's all this buzz about data science? The following videos will give…

8 years ago

Import excel files with a dynamic starting row

Go to Master Data Analysis This is the 4th post of a series that covers…

8 years ago

Import specific cells from Excel files

Go to Master Data Analysis This is the 5th post of a series that covers…

8 years ago