
Only first header will be merged into the new file ( newFileName)

If True assumes that all files have headers (first row with columns). The name of the new merged file that is to be created MergeFiles fileNames, "C:\Merged.csv", True, FalseĪrray of Strings representing full file paths to files that are to be merged
#Csv file merge tool how to#
See an example below of how to use the MergeFiles procedure: Result = result & IIf(addNewLine, vbNewLine, "") & textData Result = result & IIf(addNewLine, vbNewLine, "") & IIf(firstHeader, textData, Right(textData, Len(textData) - InStr(textData, vbNewLine))) Sub MergeFiles(fileNames() As String, newFileName As String, Optional headers As Boolean = True, Optional addNewLine As Boolean = False)ĭim fileName As Variant, textData As String, fileNo As Integer, result As String, firstHeader As Boolean It will merge all provided csv or text files into a single new text file.

If you don’t know how to use Macros in Excel read my Tutorial first.Īssuming you want to merge a list of files in a String Array you can use the procedure below. The below and the following approaches will provided you with more flexibility when merging files. The previous method was very simple and didn’t require the use of Excel or MS Office. Simply replace *.csv with *.txt to merge text files instead of CSV files Merge list of csv, txt files The result will be the newly created merge.csv file with merged data across all CSV files within the directory. Type the following command and hit ENTER to merge files The CMD Windows command line Window should open. These should be without headers or only the first file should be with headers.Ĭlick on the filepath of the Windows Explorer window and type cmd and hit ENTER. Open in Windows Explorer the folder containing CSV or TXT files to be merged. Open the folder which should contain your CSV or TXT files This approach uses the Windows Command line Copy command.

Let’s start with the simplest approach using Windows Command line without having to use Excel.
