rgb192
asked on
combine 13 similar files (without opening each and copy paste)
my bank has csv statements for each month (I called and they do not have for all year)
so how can I combine 13 files
first file downloaded is datafile0.csv to datafile12.cvs
so how can I combine 13 files
first file downloaded is datafile0.csv to datafile12.cvs
rgb192,
The attached skips row 1 for all files except the first. The code is...
Brian.Merge-CSV-s-V2.xlsm
The attached skips row 1 for all files except the first. The code is...
Option Explicit
Sub Merge_CSVs()
Dim xCSVFileName As Variant
Dim xCSVFile As Workbook
Dim xBook As Workbook
Dim xSheet As Worksheet
Dim xOut_Last As Long
Dim xCSV_Last As Long
Dim xCount As Long
Set xSheet = Sheets.Add
Application.ScreenUpdating = False
For Each xCSVFileName In Array("datafile0.csv", "datafile1.csv", "datafile2.csv", "datafile3.csv", "datafile4.csv", "datafile5.csv", "datafile6.csv" _
, "datafile7.csv", "datafile8.csv", "datafile9.csv", "datafile10.csv", "datafile11.csv", "datafile12.csv")
Set xCSVFile = Workbooks.Open("D:\" & xCSVFileName)
xCount = xCount + 1
If xCount <> 1 Then xOut_Last = xSheet.Range("A1").SpecialCells(xlLastCell).Row
xCSV_Last = ActiveSheet.Range("A1").SpecialCells(xlLastCell).Row
ActiveSheet.Range(IIf(xCount = 1, 1, 2) & ":" & xCSV_Last).Copy Destination:=xSheet.Range("A" & xOut_Last + 1)
xCSVFile.Close savechanges:=False
Next
Application.ScreenUpdating = True
End Sub
Regards,Brian.Merge-CSV-s-V2.xlsm
ASKER
yes row 1 is the header
how do I run your code
can I create a file in notepad and right click on your code on the desktop
how do I run your code
can I create a file in notepad and right click on your code on the desktop
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Thanks, rgb192.
Please see attached. Let me know if you want the second and subsequent files to skip a header row.
The code is...
Open in new window
Regards,Brian.Merge-CSV-s.xlsm