Excel is the most widely used tool for dealing with massive datasets. We can perform myriads of tasks of multiple dimensions in Excel. This article will show you how to merge multiple CSV files into one Excel workbook.
3 Easy Ways to Merge Multiple CSV Files into One Workbook in Excel
CSV files stand for Comma Separated Values files. Excel preserves data in tabular form in CSV files. These files consume less space on your computer.
I have a folder that contains 2 CSV files. The folder is on my Desktop.
I will use them and explain 3 easy ways to merge multiple CSV files into one Excel workbook.
1. Apply CMD Command to Merge Multiple CSV Files into One Workbook
First, I will show how to use the Command prompt. Let’s see the process step by step.
Steps:
- First of all, select the folder that contains the CSV
- Then, hold the SHIFT key and right-click your mouse.
- After that, select Copy as path from the context menu.
- Then, go to the Windows search box.
- After that, type cmd.
- Then, select the command prompt.
- Command Prompt box will arrive.
- Type cd followed by a space.
- Then, paste the folder path. Your command prompt window will look like this.
- Then, press ENTER. A new directory will appear.
- After that, type copy *.csv merged.csv
- “merged” is the name of the new file with the combined dataset.
- Then, press ENTER.
- Excel will create a new file.
Read More: Merge CSV Files into Multiple Sheets in Excel (with Easy Steps)
2. Use PowerQuery Feature to Merge Multiple CSV Files
The next method is the use of the PoweQuery feature.
Steps:
- First of all, open a new workbook.
- Then, go to the Data
- After that, select Get Data.
- Then, choose From File.
- After that, select From Folder.
- Then, select the folder that contains the CSV
- After that, click Open.
- Excel will open a PowerQuery
- Select Combine & Load.
- A Combine Files box will appear.
- Then, click OK.
- Excel will merge all the data.
Read More: How to Merge CSV Files in Excel (2 Easy Ways)
Similar Readings
- Open CSV File in Excel Without Formatting (2 Easy Ways)
- How to Open Notepad or Text File in Excel with Columns (3 Easy Methods)
- Excel VBA: Read a Text File Line by Line (6 Related Examples)
- How to Fix CSV File in Excel (5 Common Problems)
- How to Compare 2 CSV Files in Excel (6 Easy Ways)
3. Apply VBA Macro to Merge Multiple CSV Files into One Workbook
Now, I will use a VBA macro to merge multiple CSV files.
Steps:
- Press ALT + F11 to open the VBA window.
- Then go to Insert >> select Module.
- A new module will open. Write down the following code in the module
Sub MergeCsvs()
Dim folderpath As String
folderpath = "C:\Users\Me\Desktop\CSV Files"
If folderpath Like "*[!\/]" Then
folderpath = folderpath & "/"
End If
Dim File As String
File = Dir(folderpath & "*.csv")
Dim workbook_result As WorkBook
Set workbook_result = Workbooks.Add
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim WorkBook As WorkBook
While File <> vbNullString
Set WorkBook = Workbooks.Open(folderpath & File)
WorkBook.ActiveSheet.UsedRange.Copy workbook_result. _
ActiveSheet.UsedRange.Rows(workbook_result.ActiveSheet. _
UsedRange.Rows.Count).Offset(1).Resize(1)
WorkBook.Close False
File = Dir()
Wend
workbook_result.ActiveSheet.Rows(1).EntireRow.Delete
End Sub
Code Explanation
- MergeCsvs is the new sub-procedure
- folderpath, File, workbook_result, and WorkBook are the variables.
- “C:\Users\Me\Desktop\CSV Files” is the folder path.
- I have used the while loop here.
- Press F5 to run the code.
- Excel will create a new file and merge all the data.
- Delete the column headings that appear more than once.
Read More: How to Sort CSV File in Excel (2 Quick Methods)
Things to Remember
- For the Command Prompt method, keep the folder on your C
- The datasets should have the same headings for the PowerQuery
Conclusion
In this article, I have explained 3 easy ways to merge multiple CSV files into one Excel workbook. I hope it helps everyone. If you have any suggestions, ideas, or feedback, please feel free to comment below. Please visit Exceldemy for more useful articles like this.
Related Articles
- How to Read CSV File in Excel (4 Fastest Ways)
- How to Convert CSV to XLSX without Opening (5 Easy Methods)
- [Solved:] Excel Is Opening CSV Files in One Column (3 Solutions)
- How to Open CSV File in Excel with Columns Automatically (3 Methods)
- Excel VBA: Import Comma Delimited Text File (2 Cases)
- How to Open CSV File with Columns in Excel (3 Easy Ways)