Paul The Programmer

North East Software and Websites

60 Second Blog

Merging CSV files Into A Single XLS spreadsheet

Posted at 11:48 AM on January 05, 2009

Twitter user, v1p1n,  asked ...  "I have three csv files (comma seperated). I want to merge these csv files to a single xls files with 3 csv files in 3 tabs of the xls. Please let me know how i can do this..... "

Here's some code to get you started, this will merge 3 CSV files (FILE1,FILE2 and FILE3) into a single sheet. You'll need to modify strFilePath to the path the the CSV files...

Sub CSVFiles()
   MergeCSVFile "FILE1.CSV", "Sheet1"
   MergeCSVFile "FILE2.CSV", "Sheet2"
   MergeCSVFile "FILE3.CSV", "Sheet3"

End Sub

Sub MergeCSVFile(strCSVName As String, strSheetID As String)

   strFilePath = "c:\temp\"
    Workbooks.Open Filename:=strFilePath & strCSVName
    Windows(strCSVName).Activate
    Cells.Select
    Selection.Copy
    Windows("Book1").Activate
    Sheets(strSheetID).Select
    Cells.Select
    ActiveSheet.Paste
    Range("A1").Select
End Sub

Categories: VBA (or how to go insane)

Post a Comment

Already a member? Sign In

0 Comments

Dont Miss a thing.

Get FREE updates from me by email. Get a mini profile that lives on my website. Learn and teach. Communicate and share ideas with other members. Join here.

Recent Blog Entries

by paultheprogrammer | 0 comments
by paultheprogrammer | 1 comments
by paultheprogrammer | 0 comments
by paultheprogrammer | 2 comments

Recent Forum Posts

by paultheprogrammer 11 months ago

Recent Videos