consolidate multiple CSV files into 1 Sheet on one workbook

Alexandra12

New Member
Joined
May 29, 2008
Messages
33
Hello Guys,


I have not been on this post for a long time and I am a bit out of practice.

I was looking on the forum for a piece of code that will take multiple CSV files from multiple subfolders and load the data into 1 sheet.

Can anyone recommend how I can change the below code to do this as the below code only works for XLS


Sub CombineSubfolderFiles()
'copies rows from first worksheet of all Excel files in first subfolders
'level of a given folder.
Dim Fs As Object 'FileSystem
Dim D As Object 'Folder
Dim Fx As Object 'Subfolder
Dim File As Object 'File
Dim PathName As String
Dim iRow As Long 'next available row index of destination worksheet
Dim LRow As Long 'last row of source worksheet
With Worksheets(1) 'data destination worksheet
Set Fs = CreateObject("Scripting.FileSystemObject")
Set D = Fs.GetFolder("C:\Documents and Settings\ieu92786\Desktop\Green Sigma\North Commander II\gsextract\2009\")
iRow = 1
For Each Fx In D.subfolders 'loop through subfolders
For Each File In Fx.Files 'loop through files
If File.Name Like "*.csv" Then
PathName = Fx.Name & "\" & File.Name
Workbooks.Open D.path & "\" & PathName
Application.StatusBar = "Processing " & PathName
'copy rows to last row having data in column A
LRow = Worksheets(1).Range("A65536").End(xlUp).Row
Range(Rows(1), Rows(LRow)).Copy Destination:=.Rows(iRow)
ActiveWorkbook.Close
End If
iRow = iRow + LRow
Next File
Next Fx
End With 'Worksheets(1) of this workbook
End Sub


Also, I was wondering that is it correct to say that a CSV file will take an infinite amount of rows as their is no limitations like xls has ?

Thanks in advance
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,213,534
Messages
6,114,184
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top