I created a macro which basically does what I want. However, for some reason it always adds 10 additional empty lines in the CSV (shown as commas). When the end user offers the CSV to the external portal, this always creates 10 empty records. What should be removed or adjusted in the macro to avoid this?
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
'change folder path of excel files here
Set dirObj = mergeObj.Getfolder("\\chr-fss001\DataJapan\Sagawa\Sagawa_CSV\")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
'change "A2" with cell reference of start point for every files here
'for example "B3:IV" to merge all files start from columns B and rows 3
'If you're files using more than IV column, change it to the latest column
'Also change "A" column on "A65536" to the same column as start point
Range("A1:DZ1" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
'Do not change the following column. It's not the same column as above
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
)), TrailingMinusNumbers:=True
ActiveSheet.Shapes.Range(Array("Button 1")).Select
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Range("I1").Select
Sheets("Sheet1").Select
Columns("I:L").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Blad1").Select
Columns("I:I").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Cells(Lastrow, "A").Select
ActiveCell.Offset(1).Select
ActiveCell.EntireRow.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A1").Select
ChDir "J:\Sagawa\DailyPortalFile"
ActiveWorkbook.SaveAs Filename:= _
"J:\Sagawa\DailyPortalFile\" & Format(Now, "yyyy-mm-dd hh mm") & " Sagawa", FileFormat:=xlCSV, _
CreateBackup:=False
End Sub